var serverScaleTable;
var divideScaleData;
(function () {
	var serverSelectFuData = {};
    var serverSelectFuTable;
	// 获取合同列表页面数据 服务器分页
    var serverData = {};
    var serverTable;//合同列表
    var serverData2 = {};
    var serverTable2;//要点审批表
    var serverCruxDateData = {};
    var serverCruxDateTable;//合同关键点列表
    var serverThreeData = {};
    var serverThreeTable;
    jQuery(document).ready(function () {
    	var beforeId = jQuery('#contractId').val();
    	if(beforeId != ""){
    		jQuery.ajax({
    			type : 'get',
    			url : window.rootPath+ '/ui/contract/audit-view/'+beforeId+'/json',
    			dataType : 'json',
    			contentType : 'application/json;charset=utf-8',
    			success : function(data) {
    				var debugDate = new Date(data.contract.debugDate).toLocaleDateString();
    				if(debugDate != '1970年1月1日' && debugDate != 'Invalid Date'){
    					jQuery('#debugDate').val(debugDate);
    				}else{
    					jQuery('#debugDate').val("");
    				}
    				var deliveryDate = new Date(data.contract.deliveryDate).toLocaleDateString();
    				if(deliveryDate != '1970年1月1日' && deliveryDate != 'Invalid Date'){
    					jQuery('#deliveryDateNew').val(deliveryDate);
    				}else{
    					jQuery('#deliveryDateNew').val("");
    				}
    				var acceptanceDate = new Date(data.contract.acceptanceDate).toLocaleDateString();
    				if(acceptanceDate != '1970年1月1日' && acceptanceDate != 'Invalid Date'){
    					jQuery('#acceptanceDate').val(acceptanceDate);
    				}else{
    					jQuery('#acceptanceDate').val("");
    				}
    				
    			}
    		});
    	}
    	
    	serverTable = jQuery('#dataTable').DataTable({
    		scrollX:true,
    		scrollY:false,
    		fixedColumns : {
                leftColumns : 3
            },
            iDisplayLength:10,
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/contract/getpage1',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                {
                	data: null
                },
                {
    	            data: null,
    	            defaultContent: "",
    	            render: function (data, type, full, meta) {
    	            	var id=data.id
    	            	var operate ='<input type="checkbox" class="checkchildContract">';
    	            	return operate;
    	            }   
                },
                {
                    data: 'supplierCode',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                	data: 'contractType'
                },
                /*{
               	 data: 'auditState',
                 render: function (data, type, full, meta) {
                  	var dOut;
                  	 if(data=='审批中'){
                  		dOut = '<td class="center" ><span class="badge label-pill label-primary">审批中</span></td>';
                  	}
                  	else if(data=='驳回'){
                  		dOut = '<td class="center" ><span class="badge label-pill label-danger">驳回</span></td>';
                  	}
                  	else if(data=='通过'){
                  		dOut = '<td class="center" ><span class="badge label-pill label-success">通过</span></td>';
                  	}
                  	else  if(data=='未提交'){
                  		dOut = '<td class="center" ><span class="badge label-pill label-default">未提交</span></td>';
                  	}
                 	else  if(data=='已提交'){
                  		dOut = '<td class="center" ><span class="badge label-pill label-warning">已提交</span></td>';
                  	}
  	            	return dOut;
                  }
                
                },*/
                {
                	data: 'cstate'
                },
                {
                	data: 'state'
                },
                {
                    data: 'belongArea'
                },
                {
                    data: 'totalSum'
                },
                {
                	data: 'createTime',
                	render: function (data, type, full, meta) {
                		if (data)
                			return moment(data).format('YYYY/MM/DD');
                		else
                			return '';
                	}
                },
                {
                    data: 'signedDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'scheduleDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'giveOutDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'deliveryDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'debugDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'acceptanceDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'stop',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'freightCharge'
                },
                {
                    data: 'projectName',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'orderUnit',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'orderAddress',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'orderDelegate',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'orderPhone',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'orderZip'
                },
                {
                    data: 'orderArea'
                },
                {
                    data: 'postUnit',
	                render:function(data,type,full,meta){
						if(data == null || data == undefined || data == ""){
							return '<font title=" ">'+'</font>';
						}else{
							return '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>';
						}
					}
                },
                {
                    data: 'postAddress',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'postDelegate'
                },
                {
                    data: 'postPhone',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 11) ? '<font title="'+data+'">'+data.substring(0,11)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'postZip'
                }
                ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    	
    	serverCruxDateTable = jQuery('#resultCruxDateTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "iDisplayLength": 5,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/contract/getCruxDatepage',
                "data": function (d) {
                    return $.extend({}, d, serverCruxDateData);
                }
            },
            columns: [
                {
                	data: null
                },
                {
    	            data: null,
    	            defaultContent: "",
    	            render: function (data, type, full, meta) {
    	            	var id=data.id
    	            	var operate ='<input type="checkbox" class="checkchildCruxDate">';
    	            	return operate;
    	            }   
                },
                {
                    data: 'executiveDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'executiveType'
                },
                {
                    data: 'user.empLogin.name'
                },
                {
                    data: 'memo'
                }
                ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    	
    	//暂停合同
    	jQuery('.suspendBtn').on('click', function () {
    		var selects=getSelect("#dataTable",1);
    		if(selects.length>1){
 			   $.springLemonDialog({
 			         content: '只能编辑一条记录',// 确认文本
 			         clickButton: function (sender, modal, index) {// 按钮事件处理
 			             $(this).closeDialog(modal);
 			         }
 			   }); 
 		   }else if(selects.length==0){
 		   		$.springLemonDialog({
 		   			content: '请选择暂停的记录',// 确认文本
 		   			clickButton: function (sender, modal, index) {// 按钮事件处理
 		   				$(this).closeDialog(modal);
	 		         }
 		   			}); 
	 		   	}else{
	 			   var flag = true;
	 			   var id=selects[0].contractId;
	 			   var type=selects[0].contractType;
	 			  if(selects[0].state=="暂停"){
	 	 			   $.springLemonDialog({
	 	 			         content: '该记录已是暂停状态',// 确认文本
	 	 			         clickButton: function (sender, modal, index) {// 按钮事件处理
	 	 			             $(this).closeDialog(modal);
	 	 			         }
	 	 			   });
	 	 			   return;
	 			  }else{
	 			   $.springLemonDialog({
	 			         content: '确认暂停该记录？',// 确认文本
	 			         clickButton: function (sender, modal, index) {// 按钮事件处理
	 			        	 if (index == 0) {
	 			        		 var url=window.rootPath+"/ui/contract/suspendAndRevocationContract/"+ id +"/"+ type + "/暂停";
	 		                        jQuery.ajax({
	 		                        	url:encodeURI(url),
		 		               	        type:'get',
		 		               	        dataType:'json',
		 		               	        contentType:'application/json;charset=utf-8',
	 		                            success:function(data){
	 		                                serverTable.draw(false);
	 		                                $("#checkAllContract").prop("checked", false);
	 		                            }
	 		                        });
	 			        	 }
	 			             $(this).closeDialog(modal);
	 			         }
	 			       });  
	 			  }
	 		   }
    	});
    	
    	//终止合同
    	jQuery('.terminationBtn').on('click', function () {
    		var selects=getSelect("#dataTable",1);
    		if(selects.length>1){
    			$.springLemonDialog({
    				content: '只能终止一条记录',// 确认文本
    				clickButton: function (sender, modal, index) {// 按钮事件处理
    					$(this).closeDialog(modal);
    				}
    			}); 
    		}else if(selects.length==0){
    			$.springLemonDialog({
    				content: '请选择终止的记录',// 确认文本
    				clickButton: function (sender, modal, index) {// 按钮事件处理
    					$(this).closeDialog(modal);
    				}
    			}); 
    		}else{
    			var flag = true;
    			var id=selects[0].contractId;
    			var type=selects[0].contractType;
    			if(selects[0].state=="终止"){
	 	 			   $.springLemonDialog({
	 	 			         content: '该记录已是终止状态',// 确认文本
	 	 			         clickButton: function (sender, modal, index) {// 按钮事件处理
	 	 			             $(this).closeDialog(modal);
	 	 			         }
	 	 			   });
	 	 			   return;
	 			  }else{
					$.springLemonDialog({
						content: '确认终止该记录？',// 确认文本
						clickButton: function (sender, modal, index) {// 按钮事件处理
							if (index == 0) {
								var url=window.rootPath+"/ui/contract/suspendAndRevocationContract/"+ id +"/"+ type + "/终止";
								jQuery.ajax({
									url:encodeURI(url),
									cache:false,
									type : "get",
									dataType:"json",
									success:function(data){
										serverTable.draw(false);
										$("#checkAllContract").prop("checked", false);
									}
								});
							}
							$(this).closeDialog(modal);
						}
					}); 
	 			  }
    		}
    	});
    	//撤销合同
    	jQuery('.revocationBtn').on('click', function () {
    		var selects=getSelect("#dataTable",1);
    		if(selects.length>1){
 			   $.springLemonDialog({
 			         content: '只能撤销一条记录',// 确认文本
 			         clickButton: function (sender, modal, index) {// 按钮事件处理
 			             $(this).closeDialog(modal);
 			         }
 			   }); 
 		   }else if(selects.length==0){
	   		$.springLemonDialog({
	   			content: '请选择撤销的记录',// 确认文本
	   			clickButton: function (sender, modal, index) {// 按钮事件处理
	   				$(this).closeDialog(modal);
 		         }
	   			}); 
 		   	}else{
 			   var flag = true;
 			   var id=selects[0].contractId;
 			   var type=selects[0].contractType;
 			  if(selects[0].state=="正常"){
	 			   $.springLemonDialog({
	 			         content: '该记录已是正常状态',// 确认文本
	 			         clickButton: function (sender, modal, index) {// 按钮事件处理
	 			             $(this).closeDialog(modal);
	 			         }
	 			   });
	 			   return;
			  }else{
 			   $.springLemonDialog({
 			         content: '确认撤销该记录？',// 确认文本
 			         clickButton: function (sender, modal, index) {// 按钮事件处理
 			        	 if (index == 0) {
 			        		 var url=window.rootPath+"/ui/contract/suspendAndRevocationContract/"+ id +"/"+ type + "/撤销";
 		                        jQuery.ajax({
 		                            url:encodeURI(url),
 		                            cache:false,
 		                            type : "get",
 		                            dataType:"json",
 		                            success:function(data){
 		                                serverTable.draw(false);
 		                                $("#checkAllContract").prop("checked", false);
 		                            }
 		                        });
 			        	 }
 			             $(this).closeDialog(modal);
 			         }
 			       });  
			  }
 		   }
    	});
    	
    	// 删除合同
    	jQuery('.delBtn').on('click', function () {
    		   var selects=getSelect("#dataTable",1);
    		   if(selects.length==0){
    		       $.springLemonDialog({
    		         content: '请选择删除的记录',// 确认文本
    		         clickButton: function (sender, modal, index) {// 按钮事件处理
    		             $(this).closeDialog(modal);
    		         }
    		       }); 
    		   }else{
    			   var flag = true;
    			   var ids=selects[0].contractId;
    			   var types=selects[0].contractType;
    			   if(selects[0].cstate!='未排产'){
    				   flag = false;
    			   }
    			   for(var i=1;i<selects.length;i++){
    				   ids += ',' + selects[i].contractId;  
    				   types += ',' + selects[i].contractType;
    				   if(selects[i].cstate!='未排产'){
        				   flag = false;
        			   }
    			   }
    			   if (flag==false){
    				   $.springLemonDialog({
    	    		         content: '存在已排产的合同，请重新选择！',// 确认文本
    	    		         clickButton: function (sender, modal, index) {// 按钮事件处理
    	    		             $(this).closeDialog(modal);
    	    		         }
    	    		       });
   	    	   	       return;
    			   }
    			   $.springLemonDialog({
    			         content: '确认删除'+selects.length+'条记录？',// 确认文本
    			         clickButton: function (sender, modal, index) {// 按钮事件处理
    			        	 if (index == 0) {
    			        		 var url=window.rootPath+"/ui/contract/"+"?contractInfo="+ ids +":"+ types;
    		                        jQuery.ajax({
    		                            url:encodeURI(url),
    		                            cache:false,
    		                            type : "delete",
    		                            dataType:"json",
    		                            success:function(data){
    		                                serverTable.draw(false);
    		                                $("#checkAllContract").prop("checked", false);
    		                            }
    		                        });
    			        	 }
    			             $(this).closeDialog(modal);
    			         }
    			       });  
    		   }
    		});
        
    	jQuery('.printBtn').on('click', function () {
    		var selects=getSelect("#dataTable",1);
 		   if(selects.length>1){
 			   $.springLemonDialog({
 			         content: '只能打印一条记录',// 确认文本
 			         clickButton: function (sender, modal, index) {// 按钮事件处理
 			             $(this).closeDialog(modal);
 			         }
 			   }); 
 		   }
 		   else if(selects.length==0){
 			   $.springLemonDialog({
 			         content: '请选择要打印的记录',// 确认文本
 			         clickButton: function (sender, modal, index) {// 按钮事件处理
 			             $(this).closeDialog(modal);
 			         }
 			   }); 
 		   }else if(selects.length==1){
 			    var contractType = selects[0].contractType;
 			    /*if(contractType != "备件合同"){
 			    	$.springLemonDialog({
							content : '该合同不是备件合同，不能打印邮寄信息',// 确认文本
							clickButton : function(sender, modal, index) {// 按钮事件处理
								$(this).closeDialog(modal);
							}
						});
 			    }else{*/
 			    	var url=window.rootPath+'/ui/contract/printbj/'+selects[0].customerId;
			 		  window.location=url;
 			    //}
 			}
    	});
        // 编辑合同
    	jQuery('.editBtn').on('click', function () {
    	       var selects=getSelect("#dataTable",1);
    		   if(selects.length>1){
    			   $.springLemonDialog({
    			         content: '只能编辑一条记录',// 确认文本
    			         clickButton: function (sender, modal, index) {// 按钮事件处理
    			             $(this).closeDialog(modal);
    			         }
    			   }); 
    		   }
    		   else if(selects.length==0){
    			   $.springLemonDialog({
    			         content: '请选择要编辑的记录',// 确认文本
    			         clickButton: function (sender, modal, index) {// 按钮事件处理
    			             $(this).closeDialog(modal);
    			         }
    			   }); 
    		   }else if(selects.length==1){
    			    var auditState = selects[0].auditState;
    			    var cstate = selects[0].cstate;
    			    if(cstate == "已完成"){
    			    	$.springLemonDialog({
							content : '该合同已经生产商品计划，不能编辑',// 确认文本
							clickButton : function(sender, modal, index) {// 按钮事件处理
								$(this).closeDialog(modal);
							}
						});
    			    }
					/*if (auditState == '审批中' || auditState == '已提交') {
						$.springLemonDialog({
							content : '审批中，不能编辑',// 确认文本
							clickButton : function(sender, modal, index) {// 按钮事件处理
								$(this).closeDialog(modal);
							}
						});
					} else if (auditState == '通过') {
						$.springLemonDialog({
							content : '已经通过审批，不能编辑',// 确认文本
							clickButton : function(sender, modal, index) {// 按钮事件处理
								$(this).closeDialog(modal);
							}
						});
					} */
    			    else {
						var id=selects[0].contractId;
		    			var type=selects[0].contractType;
		    			var url=window.rootPath+'/ui/contract/contractEdit/'+ id +'/'+ type;
		    			window.location.href = url;
					}
    			   
    		   }
    		});
    	
    	// 合同关键点录入，显示弹窗
    	jQuery('.editDateBtn').on('click', function () {
    	   var selects=getSelect("#dataTable",1);
  		   if(selects.length>1){
  			   message("只能编辑一个合同");
  		   }
  		   else if(selects.length==0){
  			   message("请选择要编辑的合同");
  		   }else if(selects.length==1){
  			   var id=selects[0].contractId;
 			   var type=selects[0].contractType;
 			   var state=selects[0].auditState;
 			   /*if (state == '审批中' || state == '已提交' || state == '通过'){
 				   message("审批中或已通过审批，不能编辑");
 			   } else */
 			   if (id!=''&&type!=''){
 				   	 jQuery('#contractId').val(id);
 					 jQuery('#contractType').val(type);
 					 jQuery('#supplierCode').val(selects[0].supplierCode);
 					 jQuery('#cruxDateId').val('');
 					 jQuery('#cruxDatecreateTime').val('');
 					 jQuery('#executiveDate').val('');
 					 jQuery('#executiveType').val('');
 					 jQuery('#memo').val('');
 					 serverCruxDateData.contractId=id;
 					 serverCruxDateTable.draw(false);
 					 jQuery('#editCruxDateModal').modal('show');
	 	       } else{
	 	    	   message("合同或不存在，请刷新后重试！");
	 	       }
  		   }
    	});
    	
    	// 合同关键点编辑
    	jQuery('.editCruxDateBtn').on('click', function () {
    	   var selects=getSelect("#resultCruxDateTable",1);
  		   if(selects.length>1){
  			   message("只能编辑一个关键点");
  		   }
  		   else if(selects.length==0){
  			   message("请选择要编辑的关键点");
  		   }else if(selects.length==1){
  			   var id=selects[0].id;
 			   if (id!=''){
 				   jQuery('#cruxDateId').val(selects[0].id);
 				   jQuery("#cruxDatecreateTime").val(selects[0].createTime);
 				   jQuery('#executiveDate').val(moment(selects[0].executiveDate).format("YYYY-MM-DD"));
 				   jQuery('#executiveType').val(selects[0].executiveType);
 				   jQuery('#memo').val(selects[0].memo);
	 	       } else{
	 	    	   message("关键点或不存在，请刷新后重试！");
	 	       }
  		   }
    	});
    	
    	// 合同关键点保存
    	jQuery('.saveCruxDateBtn').on('click', function () {
    		if(jQuery("#editCruxDateAtrrForm") && !jQuery("#editCruxDateAtrrForm").Validform({tiptype:3, showAllError:true}).check(false)){
            	return;
	        };
	        jQuery(".saveCruxDateBtn").attr("disabled", true);
    		var id=jQuery("#cruxDateId").val();
    		var createTime=jQuery("#cruxDatecreateTime").val();
            var contractID=jQuery("#contractId").val();
            var contractType=jQuery("#contractType").val();
            var supplierCode=jQuery("#supplierCode").val();
            var executiveDate=jQuery("#executiveDate").val();
            var executiveType=jQuery("#executiveType").val();
            var typeNum=10;
            var memo=jQuery("#memo").val();
            if (contractID==""){
            	return;
            }
            if (executiveType=="调试完成时间"){
            	typeNum=20;
           	} else if (executiveType=="验收完成时间"){
           		typeNum=30;
           	}
            var url = window.rootPath + '/ui/contract/saveContractCruxDate';
            if (id==""){
            	var data = {
            			"contractID": contractID,
            			"contractType": contractType,
                        "executiveDate": executiveDate,
                        "executiveType": executiveType,
                        "typeNum": typeNum,
                        "memo": memo,
                    };
            } else{
            	var data = {
            			"id": id,
            			"createTime": createTime,
            			"contractID": contractID,
            			"contractType": contractType,
                        "executiveDate": executiveDate,
                        "executiveType": executiveType,
                        "typeNum": typeNum,
                        "memo": memo,
                    };
            }
            jQuery.ajax({
    	        url:encodeURI(url),
    	        type:'post',
    	        data:JSON.stringify(data),
    	        dataType:'json',
    	        contentType:'application/json;charset=utf-8',
    	        success: function () {
    	        	jQuery('#cruxDateId').val('');
    	        	jQuery('#cruxDatecreateTime').val('');
    	        	jQuery('#executiveDate').val('');
    	        	jQuery('#executiveType').val('');
    	        	jQuery('#memo').val('');
    	        	serverCruxDateTable.draw(false);
    	        	serverTable.draw(false);
    	        	jQuery(".saveCruxDateBtn").attr("disabled", false);
    	        }
    	     });
    	});
    	
    	//删除合同关键点
    	jQuery('.delCruxDateBtn').on('click', function () {
    		var selects=getSelect("#resultCruxDateTable",1);
    		var url=window.rootPath+"/ui/contract/deleteContractCruxDate";
    		$("#checkAllCruxDate").prop("checked", false);
    		if(selects.length==0){
    		       message("请选择删除的记录");
    		   }else{
    			   var ids=selects[0].id;
    			   for(var i=1;i<selects.length;i++){
    				   ids += ',' + selects[i].id;  
    			   }
    			   var api=url+"?ids="+ids;
    			   $.springLemonDialog({
    			         content: '确认删除'+selects.length+'条记录？',// 确认文本
    			         clickButton: function (sender, modal, index) {// 按钮事件处理
    			        	 if (index == 0) {
    			        		 jQuery(".btn").attr("disabled", true);
    			        		 jQuery.ajax({
    			        			    url:encodeURI(api),
    			        	            cache:false,
    			        	            type :"get",
    			        	            dataType:"json",
    			        	            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
    			        	            success:function(data){
    			        	            	jQuery(".btn").attr("disabled", false);
    			        	            	serverCruxDateTable.draw(false);
    			            	        	serverTable.draw(false);
    			        	            }
    			        	        });	
    			        	 }
    			             $(this).closeDialog(modal);
    			         }
    			       });  
    		   }
    	});
    	
    	// 查看合同
    	jQuery('.seeBtn').on('click', function () {
    		var selects=getSelect("#dataTable",1);
 		   if(selects.length>1){
 			   $.springLemonDialog({
 			         content: '只能查看一条记录',// 确认文本
 			         clickButton: function (sender, modal, index) {// 按钮事件处理
 			             $(this).closeDialog(modal);
 			         }
 			   }); 
 		   }
 		   else if(selects.length==0){
 			   $.springLemonDialog({
 			         content: '请选择要查看的记录',// 确认文本
 			         clickButton: function (sender, modal, index) {// 按钮事件处理
 			             $(this).closeDialog(modal);
 			         }
 			   }); 
 		   }else if(selects.length==1){
 			   var taskId="0";
 			   var id=selects[0].contractId;
			   var type=selects[0].contractType;
			   var url=window.rootPath+'/ui/contract/audit-view/'+ taskId + '/' + id +'/'+ type;
			   window.location.href = url;
 		   }
    	});
        
    	// 供方合同号输入框失去焦点后验证方案编号有效性
        jQuery("#supplierCode").blur( function () { 
        	var id=jQuery("#contractId").val();
        	var code=jQuery("#supplierCode").val();
        	if (id==null||id==''){
        		id = 'null';
        	}
        	if (code!=''){
        		var urlValid=window.rootPath+"/ui/contract/validSupplierCode/"+id+"/"+code;
            	jQuery.ajax({
                    url:encodeURI(urlValid),
                    cache:false,
                    type :"get",
                    dataType:"json",
                    contentType:"application/json;charset=utf-8",// 解决返回数据中的中文乱码问题
                    success:function(data){
                    	if(data.codeState==1){
                    		$.springLemonDialog({
    							content : '供方合同号已存在，请修改！',// 确认文本
    							clickButton : function(sender, modal, index) {// 按钮事件处理
    								$(this).closeDialog(modal);
    							}
    						});
                    	}
                    }
            	});
        	}
        });
        
        // 保存合同
    	var $btn = jQuery('.saveContractBtn').on('click', function () {
    		
              saveContract1("saveContractBtn");
        });
    	
    	// 应收计划编辑弹窗
    	jQuery('.editBtn1').on('click', function () {
    		
    		jQuery('#paymentModal').modal('show');
    	});
        
    	// 查询
        jQuery('.searchBtn').on('click',function(){
        	getServerDate();
//        	if(jQuery("#supplierCode-search").val().trim()) serverData.supplierCode=jQuery("#supplierCode-search").val();
//        	if(jQuery("#contractType-search").val().trim()) serverData.contractType=jQuery("#contractType-search").val();
//        	if(jQuery("#auditState-search").val().trim()) serverData.auditState=jQuery("#auditState-search").val();
//        	if(jQuery("#belongArea-search").val().trim()) serverData.belongArea=jQuery("#belongArea-search").val();
//        	if(jQuery("#totalSum-search").val().trim()) serverData.totalSum=jQuery("#totalSum-search").val();
//        	
//        	if(jQuery("#signedDate-start-search").val()) serverData.signedDateStartDate=jQuery("#signedDate-start-search").val();
//        	if(jQuery("#signedDate-end-search").val()) serverData.signedDateEndDate=jQuery("#signedDate-end-search").val();
//        	
//        	if(jQuery("#scheduleDate-start-search").val()) serverData.scheduleDateStartDate=jQuery("#scheduleDate-start-search").val();
//        	if(jQuery("#scheduleDate-end-search").val()) serverData.scheduleDateEndDate=jQuery("#scheduleDate-end-search").val();
//        	
//        	if(jQuery("#giveOutDate-start-search").val()) serverData.giveOutDateStartDate=jQuery("#giveOutDate-start-search").val();
//        	if(jQuery("#giveOutDate-end-search").val()) serverData.giveOutDateEndDate=jQuery("#giveOutDate-end-search").val();
//        	
//        	if(jQuery("#deliveryDate-start-search").val()) serverData.deliveryDateStartDate=jQuery("deliveryDate-start-search").val();
//        	if(jQuery("#deliveryDate-end-search").val()) serverData.deliveryDateEndDate=jQuery("deliveryDate-end-search").val();
//        	
//        	if(jQuery("#debugDate-start-search").val()) serverData.debugDateStartDate=jQuery("#debugDate-start-search").val();
//        	if(jQuery("#debugDate-end-search").val()) serverData.debugDateEndDate=jQuery("#debugDate-end-search").val();
//
//        	if(jQuery("#acceptanceDate-start-search").val()) serverData.acceptanceDateStartDate=jQuery("#acceptanceDate-start-search").val();
//        	if(jQuery("#acceptanceDate-end-search").val()) serverData.acceptanceDateEndDate=jQuery("#acceptanceDate-end-search").val();
//        	
//        	if(jQuery("#stop-search").val().trim()) serverData.stop=jQuery("#stop-search").val();
//        	if(jQuery("#freightCharge-search").val().trim()) serverData.freightCharge=jQuery("#freightCharge-search").val();
//        	if(jQuery("#projectName-search").val().trim()) serverData.projectName=jQuery("#projectName-search").val();
//        	if(jQuery("#orderUnit-search").val().trim()) serverData.orderUnit=jQuery("#orderUnit-search").val();
//        	if(jQuery("#orderAddress-search").val().trim()) serverData.orderAddress=jQuery("#orderAddress-search").val();
//        	if(jQuery("#orderDelegate-search").val().trim()) serverData.orderDelegate=jQuery("#orderDelegate-search").val();
//        	if(jQuery("#orderPhone-search").val().trim()) serverData.orderPhone=jQuery("#orderPhone-search").val();
//        	if(jQuery("#orderZip-search").val().trim()) serverData.orderZip=jQuery("#orderZip-search").val();
//        	if(jQuery("#orderArea-search").val().trim()) serverData.orderArea=jQuery("#orderArea-search").val();
//        	if(jQuery("#postUnit-search").val().trim()) serverData.postUnit=jQuery("#postUnit-search").val();
//        	if(jQuery("#postAddress-search").val().trim()) serverData.postAddress=jQuery("#postAddress-search").val();
//        	if(jQuery("#postDelegate-search").val().trim()) serverData.postDelegate=jQuery("#postDelegate-search").val();
//        	if(jQuery("#postPhone-search").val().trim()) serverData.postPhone=jQuery("#postPhone-search").val();
//        	if(jQuery("#postZip-search").val().trim()) serverData.postZip=jQuery("#postZip-search").val();
        	serverTable.draw();
        	//clearQueryServerData();
        })
        
        var getServerDate=function(){
        	if(jQuery(".DTFC_LeftHeadWrapper  #supplierCode-search").val()) serverData.supplierCode=jQuery(".DTFC_LeftHeadWrapper #supplierCode-search").val();
        	if(jQuery("#contractType-search").val()) serverData.contractType=jQuery("#contractType-search").val();
        	//if(jQuery("#auditState-search").val()) serverData.auditState=jQuery("#auditState-search").val();
        	if(jQuery("#state-search").val()) serverData.state=jQuery("#state-search").val();
        	if(jQuery("#cstate-search").val()) serverData.cstate=jQuery("#cstate-search").val();
        	if(jQuery("#belongArea-search").val()) serverData.belongArea=jQuery("#belongArea-search").val();
        	
        	if(jQuery("#totalSum-search").val()) serverData.totalSumStartNum=jQuery("#totalSum-search").val();
        	if(jQuery("#totalSum-end-search").val()) serverData.totalSumEndNum=jQuery("#totalSum-end-search").val();
        	
        	if(jQuery("#createTime-start-search").val()) serverData.createTimeStartDate=jQuery("#createTime-start-search").val();
        	if(jQuery("#createTime-end-search").val()) serverData.createTimeEndDate=jQuery("#createTime-end-search").val();
        	
        	if(jQuery("#signedDate-start-search").val()) serverData.signedDateStartDate=jQuery("#signedDate-start-search").val();
        	if(jQuery("#signedDate-end-search").val()) serverData.signedDateEndDate=jQuery("#signedDate-end-search").val();
        	
        	if(jQuery("#scheduleDate-start-search").val()) serverData.scheduleDateStartDate=jQuery("#scheduleDate-start-search").val();
        	if(jQuery("#scheduleDate-end-search").val()) serverData.scheduleDateEndDate=jQuery("#scheduleDate-end-search").val();
        	
        	if(jQuery("#giveOutDate-start-search").val()) serverData.giveOutDateStartDate=jQuery("#giveOutDate-start-search").val();
        	if(jQuery("#giveOutDate-end-search").val()) serverData.giveOutDateEndDate=jQuery("#giveOutDate-end-search").val();
        	
        	if(jQuery("#deliveryDate-start-search").val()) serverData.deliveryDateStartDate=jQuery("#deliveryDate-start-search").val();
        	if(jQuery("#deliveryDate-end-search").val()) serverData.deliveryDateEndDate=jQuery("#deliveryDate-end-search").val();
        	
        	if(jQuery("#debugDate-start-search").val()) serverData.debugDateStartDate=jQuery("#debugDate-start-search").val();
        	if(jQuery("#debugDate-end-search").val()) serverData.debugDateEndDate=jQuery("#debugDate-end-search").val();

        	if(jQuery("#acceptanceDate-start-search").val()) serverData.acceptanceDateStartDate=jQuery("#acceptanceDate-start-search").val();
        	if(jQuery("#acceptanceDate-end-search").val()) serverData.acceptanceDateEndDate=jQuery("#acceptanceDate-end-search").val();
        	
        	if(jQuery("#stop-search").val()) serverData.stop=jQuery("#stop-search").val();
        	if(jQuery("#freightCharge-search").val()) serverData.freightCharge=jQuery("#freightCharge-search").val();
        	if(jQuery("#projectName-search").val()) serverData.projectName=jQuery("#projectName-search").val();
        	if(jQuery("#orderUnit-search").val()) serverData.orderUnit=jQuery("#orderUnit-search").val();
        	if(jQuery("#orderAddress-search").val()) serverData.orderAddress=jQuery("#orderAddress-search").val();
        	if(jQuery("#orderDelegate-search").val()) serverData.orderDelegate=jQuery("#orderDelegate-search").val();
        	if(jQuery("#orderPhone-search").val()) serverData.orderPhone=jQuery("#orderPhone-search").val();
        	if(jQuery("#orderZip-search").val()) serverData.orderZip=jQuery("#orderZip-search").val();
        	if(jQuery("#orderArea-search").val()) serverData.orderArea=jQuery("#orderArea-search").val();
        	if(jQuery("#postUnit-search").val()) serverData.postUnit=jQuery("#postUnit-search").val();
        	if(jQuery("#postAddress-search").val()) serverData.postAddress=jQuery("#postAddress-search").val();
        	if(jQuery("#postDelegate-search").val()) serverData.postDelegate=jQuery("#postDelegate-search").val();
        	if(jQuery("#postPhone-search").val()) serverData.postPhone=jQuery("#postPhone-search").val();
        	if(jQuery("#postZip-search").val()) serverData.postZip=jQuery("#postZip-search").val();
        }
        // 撤销查询
        jQuery('.resetBtn').on("click",function()
        {
        	clearQueryServerData('clearui');
            serverTable.draw();
        });
        
        var clearQueryServerData=function(option){
        	if(option=='clearui'){
        		 jQuery('input').val('');
                 jQuery('select').val('');
        	}
        	if(serverData.supplierCode) serverData.supplierCode=null;
        	if(serverData.contractType) serverData.contractType=null;
        	//if(serverData.auditState) serverData.auditState=null;
        	if(serverData.state) serverData.state=null;
        	if(serverData.cstate) serverData.cstate=null;
        	if(serverData.belongArea) serverData.belongArea=null;
        	
        	if(serverData.totalSumStartNum) serverData.totalSumStartNum=null;
        	if(serverData.totalSumEndNum) serverData.totalSumEndNum=null;
        	
        	if(serverData.createTimeStartDate) serverData.createTimeStartDate=null;
        	if(serverData.createTimeEndDate) serverData.createTimeEndDate=null;
        	
        	if(serverData.signedDateStartDate) serverData.signedDateStartDate=null;
        	if(serverData.signedDateEndDate) serverData.signedDateEndDate=null;
        	
        	if(serverData.scheduleDateStartDate) serverData.scheduleDateStartDate=null;
        	if(serverData.scheduleDateEndDate) serverData.scheduleDateEndDate=null;
        	
        	if(serverData.giveOutDateStartDate) serverData.giveOutDateStartDate=null;
        	if(serverData.giveOutDateEndDate) serverData.giveOutDateEndDate=null;
        	
        	if(serverData.deliveryDateStartDate) serverData.deliveryDateStartDate=null;
        	if(serverData.deliveryDateEndDate) serverData.deliveryDateEndDate=null;
        	
        	if(serverData.debugDateStartDate) serverData.debugDateStartDate=null;
        	if(serverData.debugDateEndDate) serverData.debugDateEndDate=null;

        	if(serverData.acceptanceDateStartDate) serverData.acceptanceDateStartDate=null;
        	if(serverData.acceptanceDateEndDate) serverData.acceptanceDateEndDate=null;
        	
        	if(serverData.stop) serverData.stop=null;
        	if(serverData.freightCharge) serverData.freightCharge=null;
        	if(serverData.projectName) serverData.projectName=null;
        	if(serverData.orderUnit) serverData.orderUnit=null;
        	if(serverData.orderAddress) serverData.orderAddress=null;
        	if(serverData.orderDelegate) serverData.orderDelegate=null;
        	if(serverData.orderPhone) serverData.orderPhone=null;
        	if(serverData.orderZip) serverData.orderZip=null;
        	if(serverData.orderArea) serverData.orderArea=null;
        	if(serverData.postUnit) serverData.postUnit=null;
        	if(serverData.postAddress) serverData.postAddress=null;
        	if(serverData.postDelegate) serverData.postDelegate=null;
        	if(serverData.postPhone) serverData.postPhone=null;
        	if(serverData.postZip) serverData.postZip=null;
        }
     // 引入客户信息弹窗
   	 jQuery('#queryCustomer').on("click",function(){
   		//jQuery("#queryCustomerModal").modal('show');
   		showCustomer();//显示客户信息
   	 });
   	 
   	 // 引入客户信息
	    jQuery('#pull-customer-in').on("click",function(){
	    	var selects=getSelect("#query-customer-table",1);
			if(selects.length>1){
		   		  message("只能引入一条客户");
		   	   }
		   	   else if(selects.length==0){
		   		   message("没有选中客户");
		   	   }else if(selects.length==1){
	   		   		jQuery("#orderUnit").val(selects[0].customerName);
	   			   	jQuery("#orderZip").val(selects[0].zipCode);
//	   			   	var orderArea = selects[0].saleArea.superior+"-"+selects[0].saleArea.areaName;
	   			   	jQuery("#orderArea").val(selects[0].saleArea.superiorArea);
	   			   	jQuery("#orderArea").select2().trigger("change");
	   			   	jQuery("#industryInfo").val(selects[0].business);
	   			   	jQuery("#belongArea").val(selects[0].business);//合同分类明细的所属板块也就是行业信息
	   			   	jQuery("#orderAddress").val(selects[0].address);
		   			jQuery("#invoiceBank").val(selects[0].invoiceBank);
		   			jQuery("#bankAccount").val(selects[0].bankAccount);
		   			jQuery("#taxNumber").val(selects[0].taxNumber);
		   			jQuery("#invoiceAddress").val(selects[0].invoiceAddress);
		   			jQuery("#postUnit").val(selects[0].postUnit);
	   			   	jQuery("#postDelegate").val(selects[0].postDelegate);
	   			   	jQuery("#postPhone").val(selects[0].postPhone);
	   			   	jQuery("#postAddress").val(selects[0].postAddress);
	   			   	jQuery("#postZip").val(selects[0].postZip);
	   	   	   		jQuery("#customerId").val(selects[0].id);
	   	   	   		jQuery("#orderDelegate").val(selects[0].cDHDB);
	   	   	   		jQuery("#orderPhone").val(selects[0].cDHPhone);
	   	   	   		jQuery("#query-Customer-Modal").modal('hide');
	   	   	   		var url=window.rootPath + "/ui/customer/getDefaultInfo?customerId="+selects[0].id+"&hostType="+(jQuery("#contractType").val()=="项目合同"?1:0);
		   				jQuery.ajax({
   		   					type: 'get',
   				            url:  encodeURI(url),
   				            data: JSON.stringify(""),
   				            dataType: 'json',
   				            contentType: 'application/json;charset=utf-8',
   		   					success : function(data) {
   		   						if(data.data[0]!=null){
   		   		   	   			   	jQuery("#orderZip").val(data.data[0].zipCode);
   		   		   	   			   	jQuery("#postZip").val(data.data[0].zipCode);
   		   		   	   			   	jQuery("#postPhone").val(data.data[0].invoicePhone);
   		   		   	   			   	jQuery("#orderPhone").val(data.data[0].invoicePhone);
   		   		   	   			   	jQuery("#postAddress").val(data.data[0].invoiceAddress);
   		   		   	   			   	jQuery("#invoiceAddress").val(data.data[0].invoiceAddress);
   		   		   	   			   	jQuery("#orderAddress").val(data.data[0].invoiceAddress);
   		   		   	   			   	jQuery("#invoiceBank").val(data.data[0].invoiceBank);
   		   		   	   			   	jQuery("#bankAccount").val(data.data[0].bankAccount);
   		   		   	   			   	jQuery("#taxNumber").val(data.data[0].taxNumber);
   		   						}
   		   						if(data.data[1]!=null){
   		   		   	   			   	jQuery("#postUnit").val(data.data[1].postUnit);
   		   		   	   			   	jQuery("#postDelegate").val(data.data[1].postDelegate);
   		   		   	   			   	jQuery("#postPhone").val(data.data[1].postPhone);
   		   		   	   			   	jQuery("#postAddress").val(data.data[1].postAddress);
   		   		   	   			   	jQuery("#postZip").val(data.data[1].postZip);
   		   						}
   		   					}
   		   				});
		   	   }
	    });
   	    
   	 
   	    
   	// 关联合同弹窗中合同信息table,
   	// (备件合同细目备件、备泵合同细目备泵以及维修合同细目泵的新建/编辑弹窗都使用该js,
   	// 维修合同细目其他为避免冲突使用单独的contractRepairOther.js)
    	  var serverContractData={};
    	  var serverContractTable;
    	  jQuery(document).ready(function () {

    		serverContractTable = jQuery('#resultContractTable').DataTable({
    	            "serverSide": true,
    	            "ordering": false,
    	            "iDisplayLength": 5,
    	            "ajax": {
    	                "dataType": "json",
    	                "type": "get",
    	                "cache": false,
    	                "url":window.rootPath+ '/ui/contract/getContract',
    	                "data": function (d) {
    	                    return $.extend({}, d, serverContractData);
    	                }
    	            },
    	            columns: [
    	                {
    	                	data: null
    	                },
    	                {
    	                	data : null,
    						defaultContent : "",
    						render : function(data,type, full, meta) {
    							var operate = '<button type="button" class="btn btn-info btn-sm selectBtn">选择</button>';
    							return operate;
    						}  
    	                },
    	                {
    	                    data: 'supplierCode'
    	                },
    	                {
    	                    data: 'belongArea'
    	                },
    	                {
    	                    data: 'totalSum'
    	                },
    	                {
  	                    data: 'signedDate',
  	                    render: function (data, type, full, meta) {
  	                        if (data)
  	                            return moment(data).format('YYYY/MM/DD');
  	                        else
  	                            return '';
  	                    }
    	                },
    	                {
    	                    data: 'projectName'
    	                },
    	                {
    	                    data: 'orderUnit'
    	                },
    	                {
    	                    data: 'orderArea'
    	                }
    	                ],
    	            "drawCallback": function (oSettings) {
    	                var k = 0;
    	                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

    	                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
    	                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
    	                    k++;
    	                }
    	                    serverContractTable.off('click', 'tr');
    	                    serverContractTable.on('click','tr',function(event) {
    					    event = event|| window.event;
    						var target = event.target|| event.scrElement;
    						var data = serverContractTable.row(this).data();
    						if (target.className.indexOf('selectBtn') != -1) {
    							selectContract(data);
    						}
    					return;
    					});
    	            }
    	        });
    		   // 选择合同
    		   var  selectContract=function(data){
    			    jQuery("#selectContractId").val(data.id);
					jQuery("#oneSupplierCode").val(data.supplierCode);
					jQuery("#moreSupplierCode").val(data.supplierCode);
    		   }
    	  });
    	  
    	// 查询关联的合同
        jQuery('.searchContractBtn').on('click',function(){
            serverContractData.key=jQuery('#keywordContract').val();
            serverContractTable.draw();
        })
        // 撤销查询关联的合同
        jQuery('.resetContractBtn').on("click",function()
        {
            jQuery('#keywordContract').val('');
            serverContractData.key ='';
            serverContractTable.draw();
        });
        //附加开票信息
        var serverCustomerPaytable;
        var serverCustomerPayData={};
   	    var serverCustomerPayCount=0;
 		serverCustomerPayData.CustomerId = jQuery('#customerId').val();
        serverCustomerPaytable = jQuery('#table-CustomerPay').DataTable({
            "serverSide": true,
            "ordering": false,
            "iDisplayLength": 5,
            "ajax": {
                "dataType": "json",
                "type": "post",
                "cache": false,
                "url":window.rootPath+ '/ui/customer/selectCustomer',
                "data": function (d) {
                    return $.extend({}, d, serverCustomerPayData);
                }
            },
            columns: [
                {
                	data: null
                },
                {
    	            data: null,
    	            defaultContent: "",
    	            render: function (data, type, full, meta) {
    	            	var id=data.id
    	            	var operate ='<input type="checkbox" class="checkchildCruxDate">';
    	            	return operate;
    	            }   
                },
                {
                    data: 'CustomerId'
                },
                {
                    data: 'invoicePhone'
                },
                {
                    data: 'zipCode'
                },
                {
                    data: 'invoiceAddress'
                },
                {
                    data: 'invoiceBank'
                },
                {
                    data: 'bankAccount'
                },
                {
                    data: 'taxNumber'
                },
                {
                    data: 'isDefaultHost'
                },
                {
                    data: 'isDefaultPart'
                }
                ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
        
        jQuery('#queryCustomerPayInfo').on('click', function () {
     	   var customerId=jQuery('#customerId').val();
   		   if(customerId.length==0){
   			   message("请先选择订货单位信息！");
   		   } else{
   			   serverCustomerPayData.CustomerId = customerId;
   			   serverCustomerPaytable.draw();
   			   jQuery("#modal-find-CustomerPayInfo").modal('show');
   		   }
     	});
      //切换邮寄单位信息弹窗表格
        var changePostUnitTable;
        var changePostUnitData={};
        var changePostUnitCount=0;
        changePostUnitData.CustomerId = jQuery('#customerId').val();
        changePostUnitTable = jQuery('#post-unit-table').DataTable({
            "serverSide": true,
            "ordering": false,
            "iDisplayLength": 5,
            "ajax": {
                "dataType": "json",
                "type": "post",
                "cache": false,
                "url":window.rootPath+ '/ui/customer/getMailingInfoList',
                "data": function (d) {
                    return $.extend({}, d, changePostUnitData);
                } 
            },
            columns: [
                {
                	data: null
                },
                {
    	            data: null,
    	            defaultContent: "",
    	            render: function (data, type, full, meta) {
    	            	var id=data.id
    	            	var operate ='<input type="checkbox" class="checkchildCruxDate">';
    	            	return operate;
    	            }   
                },
                {
                    data: 'postUnit'
                }
                ,
                {
                    data: 'postDelegate'
                }
                ,
                {
                    data: 'postPhone'
                }
                ,
                {
                    data: 'postZip'
                }
                ,
                {
                    data: 'postAddress'
                },
                {
                    data: 'isDefaultHost'
                },
                {
                    data: 'isDefaultPart'
                }
                ],
            "drawCallback": function (oSettings) {	
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
                
                
            }
        });
        jQuery('#changeUnitAdressBtn').on('click', function () {
     	   var customerId=jQuery('#customerId').val();
   		   if(customerId.length==0){
   			   message("请先选择订货单位信息！");
   		   } else{
 			    changePostUnitData.CustomerId = customerId;
   			    changePostUnitTable.draw();
   			   jQuery("#post-unit-modal").modal('show');
   		   }
     	});
        //引入邮寄单位信息
        jQuery('#post-unit-addBtn').on("click",function(){
	    	var selects=getSelect("#post-unit-table",1);
			if(selects.length>1){
		   		  message("只能引入一条邮寄单位信息！");
		   	   }
		   	   else if(selects.length==0){
		   		   message("没有选中邮寄单位信息！");
		   	   }else if(selects.length==1){
	   			   	jQuery("#postUnit").val(selects[0].postUnit);
	   			   	jQuery("#postDelegate").val(selects[0].postDelegate);
	   			   	jQuery("#postPhone").val(selects[0].postPhone);
	   			   	jQuery("#postAddress").val(selects[0].postAddress);
	   			   	jQuery("#postZip").val(selects[0].postZip);
	   			    jQuery("#post-unit-modal").modal('hide');
		   	   }
	    });
        //装入默认信息，type=1：邮寄单位信息,type=2：开票信息.hostType=1:主机默认，hostType=2:备件默认
        function addInfo(data,type){
        	if(data.length==0){
        		return;
        	}
            var needData="";//定义变量，装需要的数据
        	if(type==1){
                needData=infoDalSelect(data);
   			   	jQuery("#postUnit").val(needData.postUnit);
   			   	jQuery("#postDelegate").val(needData.postDelegate);
   			   	jQuery("#postPhone").val(needData.postPhone);
   			   	jQuery("#postAddress").val(needData.postAddress);
   			   	jQuery("#postZip").val(needData.postZip);
        	}else{
                needData=infoDalSelect(data);
   			   	jQuery("#orderZip").val(needData.zipCode);
   			   	jQuery("#postZip").val(needData.zipCode);
   			   	jQuery("#postPhone").val(needData.invoicePhone);
   			   	jQuery("#orderPhone").val(needData.invoicePhone);
   			   	jQuery("#postAddress").val(needData.invoiceAddress);
   			   	jQuery("#invoiceAddress").val(needData.invoiceAddress);
   			   	jQuery("#orderAddress").val(needData.invoiceAddress);
   			   	jQuery("#invoiceBank").val(needData.invoiceBank);
   			   	jQuery("#bankAccount").val(needData.bankAccount);
   			   	jQuery("#taxNumber").val(needData.taxNumber);
        	}
        }
        //信息筛选，选择默认信息，如果没有默认则返回第一条数据
        function infoDalSelect(data){
        	var myNeedData="";
        	var c=0;//计数位
        	for(var i=0;i<data.length;i++){
        		if(jQuery("#contractType").val()=="项目合同"){
        			if(data[i].isDefaultHost==1){
        				myNeedData=data[i];
        				c++;
        				break;
        			}
        		}else{
        			if(data.isDefaultPart==1){
        				myNeedData=data[i];
        				c++;
        				break;
        			}
        		}
        	}
        	if(c==0){
        		myNeedData=data[0];
        	}
        	return myNeedData;
        }
        //弹出新增客户信息dialog
        jQuery('#saveCustomer').on('click', function () {
        	jQuery("#identification_son").val('');
        	jQuery("#address").val('');
        	jQuery("#identifications_son").val('');
        	jQuery("#invoicePhone_son").val('');
        	jQuery("#zipCode_son").val('');
        	jQuery("#invoiceAddress_son").val('');
        	jQuery("#invoiceBank_son").val('');
        	jQuery("#bankAccount_son").val('');
        	jQuery("#taxNumber_son").val('');
        	jQuery("#postUnit_son").val('');
        	jQuery("#postDelegate_son").val('');
        	jQuery("#postPhone_son").val('');
        	jQuery("#postZip_son").val('');
        	jQuery("#postAddress_son").val('');
        	jQuery("#invoiceMemo_son").val('');
        	jQuery("#newCustomer").modal('show');
      	});
        /***
	     * 保存客户信息弹出dialog中的字段内容
	     */ 
     // 保存客户信息
    	jQuery('#son_save').on('click', function() {
    		//bqb
    		$.springLemonDialog({
	   	         content: '即将保存该界面信息，是否继续？',// 确认文本
	   	         clickButton: function (sender, modal, index) {// 按钮事件处理
	   	             $(this).closeDialog(modal);
	   	   		if(index == 0){
	   				if (jQuery("#son_customer") && !jQuery("#son_customer").Validform({
	   					tiptype : 3,
	   					showAllError : true
	   				}).check(false)) {return;}
					var id = jQuery("#customerId").val();
					var CustomerId = jQuery('#customerId').val();
					var business = jQuery("#business").find("option:selected").text();;
					var superior = jQuery("#superior").val();
					var address = jQuery("#address").val();
					var areaId = jQuery('#saleArea').val();
	   				jQuery("#son_save").attr("disabled","disabled");
	   				var api = window.rootPath + "/ui/customer/saveCustomer?customerId="+id;;
	   				var d={
	   						//"saleArea" : saleArea,
							"business" : business,
							"superior" : superior,
							"address" : address,
							"saleArea": {
			  	                "id": areaId
			  	            },
							"customerCode" : $("#customerCode").val(),
							"customerName" : $("#identification_son").val(),
							"customerId":CustomerId,
							"cDHDB" : $("#cDHDB").val(),
							"cDHPhone" : $("#cDHPhone").val(),
						};
	   				jQuery.ajax({
	   					type: 'post',
			            url:  encodeURI(api),

			            data: JSON.stringify(d),
			            dataType: 'json',
			            contentType: 'application/json;charset=utf-8',
	   					success : function(data) {
	   						//serverSelectFuData.CustomerId=data.customerId;
	   	            		//serverSelectFuTable.draw();
	   						var url1=window.rootPath + "/ui/customer/saveCustomerPayInfo";
	   						var payInfoData={
	   		   						"customer":{
	   		   							"id":data.customerId
	   		   						},
	   		   				        "isDefaultHost":jQuery("#contractType").val()=="项目合同"?1:0,
	   		   				        "isDefaultPart":jQuery("#contractType").val()=="项目合同"?0:1,
	   								"identification" : $("#identifications_son").val(),
	   								"zipCode" : $("#zipCode_son").val(),
	   								"invoicePhone" : $("#invoicePhone_son").val(),
	   								"invoiceAddress" : $("#invoiceAddress_son").val(),
	   								"invoiceBank" : $("#invoiceBank_son").val(),
	   								"bankAccount" : $("#bankAccount_son").val(),
	   								"taxNumber" : $("#taxNumber_son").val(),
	   								"invoiceMemo" : $("#invoiceMemo_son").val(),
	   		   				}
	   		   				jQuery.ajax({
	   		   					type: 'post',
	   				            url:  encodeURI(url1),

	   				            data: JSON.stringify(payInfoData),
	   				            dataType: 'json',
	   				            contentType: 'application/json;charset=utf-8',
	   		   					success : function(data) {}
	   		   				});
	   						var url2=window.rootPath + "/ui/customer/saveCustomerMailingInfo";
	   		   				var postData={
	   		   						"customer":{
	   		   							"id":data.customerId
	   		   						},
	   		   				        "isDefaultHost":jQuery("#contractType").val()=="项目合同"?1:0,
	   		   		   				"isDefaultPart":jQuery("#contractType").val()=="项目合同"?0:1,
	   								"postUnit" : $("#postUnit_son").val(),
	   								"postDelegate" : $("#postDelegate_son").val(),
	   								"postPhone" : $("#postPhone_son").val(),
	   								"postAddress" : $("#postAddress_son").val(),
	   								"postZip" : $("#postZip_son").val(),
	   		   				};
	   		   				jQuery.ajax({
	   		   					type: 'post',
	   				            url:  encodeURI(url2),
	   				            data: JSON.stringify(postData),
	   				            dataType: 'json',
	   				            contentType: 'application/json;charset=utf-8',
	   		   					success : function(data) {
	   		   						;
	   		   					}
	   		   				});
	   						jQuery("#son_save").removeAttr("disabled");
	   						jQuery('#newCustomer').modal('hide');
	   					}
	   				});
	   			
	   			}
	   	     }
	   	 });
    	});
        jQuery('#btn-reference1').on("click",function(){
	    	var selects=getSelect("#table-CustomerPay",1);
			if(selects.length>1){
		   		  message("只能引入一条开票信息！");
		   	   }
		   	   else if(selects.length==0){
		   		   message("没有选中客户！");
		   	   }else if(selects.length==1){
	   			   	jQuery("#orderZip").val(selects[0].zipCode);
	   			   	jQuery("#postZip").val(selects[0].zipCode);
	   			   	jQuery("#postPhone").val(selects[0].invoicePhone);
	   			   	jQuery("#orderPhone").val(selects[0].invoicePhone);
	   			   	jQuery("#postAddress").val(selects[0].invoiceAddress);
	   			   	jQuery("#invoiceAddress").val(selects[0].invoiceAddress);
	   			   	jQuery("#orderAddress").val(selects[0].invoiceAddress);
	   			   	jQuery("#invoiceBank").val(selects[0].invoiceBank);
	   			   	jQuery("#bankAccount").val(selects[0].bankAccount);
	   			   	jQuery("#taxNumber").val(selects[0].taxNumber);
//	   			   	jQuery("#postUnit").val(selects[0].postUnit);
//	   			   	jQuery("#postDelegate").val(selects[0].postDelegate);
//	   			   	jQuery("#postPhone").val(selects[0].postPhone);
//	   			   	jQuery("#postAddress").val(selects[0].postAddress);
//	   			   	jQuery("#postZip").val(selects[0].postZip);
	   	   	   		jQuery("#modal-find-CustomerPayInfo").modal('hide');
		   	   }
	    });
        
        // 提交合同
        jQuery('.submitBtn').on('click', function () {
        	if(jQuery("#contractAtrrForm") && !jQuery("#contractAtrrForm").Validform({tiptype:3, showAllError:true}).check(false)){
            	return;
	        };
	        saveContract1("submitBtn");
        });
        
        // 上传附件
      	jQuery(".btnUpload").on("click", function() {
      		var contractId = jQuery("#contractId").val();
      		if (contractId==""){
      			if (confirm("当前合同还未保存，是否保存？")) {
      				saveContract1("btnUpload");
            	}
      		}else{
      			var goupId = "方案附件";
          		fileUpload(contractId,goupId);
      		}
      	});
      	
      	// 下载附件
      	jQuery(".btnList").on("click", function() {
      		var contractId = jQuery("#contractId").val();
      		var goupId = "方案附件";
    		filedown(contractId,goupId,1);
    	});
      	
      	/**
      	 * 保存合同
      	 */
      	var saveContract1 = function(state,quoteId) {
      		if(jQuery("#contractAtrrForm") && !jQuery("#contractAtrrForm").Validform({tiptype:3, showAllError:true}).check(false)){
	            	return;
		        };
      		var signedDate = jQuery('#signedDate').val();
      		var giveOutDate = jQuery('#giveOutDate').val();
      		var scheduleDate = jQuery('#scheduleDate').val();
      		var operatDate = jQuery('#operatDate').val();
      		if (signedDate==""||giveOutDate==""||operatDate==""){
      			message("请将页面上所有日期信息完善，保存后还可进行编辑。");
      			return ;
      		}
      	    var isId=jQuery("#contractId").val();
      	    var contractcreateTime=jQuery("#createTime").val();
      	    var createTime=new Date(contractcreateTime).getTime();
      	    var supplierCode = jQuery('#supplierCode').val();
      		var demanderCode = jQuery('#demanderCode').val();
      		var contractType = jQuery('#contractType').val();
      		var totalSum = jQuery('#totalSum').val();
      		var stop = jQuery('#stop').val();
      		var freightCharge = jQuery('#freightCharge').val();
      		var projectName = jQuery('#projectName').val();
      	 	var payType = jQuery('#payType').val();
      	 	var guaranteePeriod = jQuery('#guaranteePeriod').val();
      	 	var breakDuty = jQuery('#breakDuty').val();
      	 	var customerId = jQuery("#customerId").val();
      		var orderUnit = jQuery('#orderUnit').val();
      	 	var orderDelegate = jQuery('#orderDelegate').val();
      		var orderPhone = jQuery('#orderPhone').val();
      		var industryInfo = jQuery('#industryInfo').val();
      		var orderAddress = jQuery('#orderAddress').val();
      		var orderZip = jQuery('#orderZip').val();
      		var orderArea = jQuery('#orderArea').val();
      		var invoiceBank = jQuery("#invoiceBank").val();
      		var bankAccount = jQuery("#bankAccount").val();
      		var taxNumber = jQuery("#taxNumber").val();
      		var invoiceAddress = jQuery("#invoiceAddress").val();
      		var postUnit = jQuery('#postUnit').val();
      	 	var postDelegate = jQuery('#postDelegate').val();
      		var postPhone = jQuery('#postPhone').val();
      		var postAddress = jQuery('#postAddress').val();
      		var postZip = jQuery('#postZip').val();
      		var dutyArea = jQuery('#dutyArea').val();
      		var dutyOfficer = jQuery('#dutyOfficer').val();
      		var southNorthArea = jQuery('#southNorthArea').val();
      		var belongArea = jQuery('#belongArea').val();
      		var checkKind = jQuery('#checkKind').val();
      		var productKind = jQuery('#productKind').val();
      		var signOfficer = jQuery('#signOfficer').val();
      		var repairOfficer = jQuery('#repairOfficer').val();
      		var quotationOfficer = jQuery('#quotationOfficer').val();
      		var operatDepartment = jQuery('#operatDepartment').val();
      		var operator = jQuery('#operator').val();
      		var memo = jQuery('#memo').val();
      		var contractState = jQuery('#state').val();
      		var cstate = jQuery('#cstate').val();
      		if (cstate=="已完成"){
      			$.springLemonDialog({
  					content : '该合同已经生产商品计划，不能保存！',// 确认文本
  					clickButton : function(sender, modal, index) {// 按钮事件处理
  						$(this).closeDialog(modal);
  					}
      			});
  			}
      		if(cstate=="已排产"){
      			alert("保存合同后将修改排产相关信息。");
      		}
      		if (contractType=="项目合同"){
      			var scheduleDate = jQuery('#scheduleDate').val();
      			if (scheduleDate==""){
      				message("请将排产日期信息完善，保存后还可进行编辑。");
      		 		return ;
      			}
      			var contract = "saveContract";
      			// 判断是编辑还是新增
      	        if(isId == ""){// 新增合同
      	        	
      	        	var d = {
      	 					"user":{"id":$("#userId").val()},
      	                	"supplierCode": supplierCode,
      	                	"demanderCode": demanderCode,
      	                	"contractType": contractType,
      	                    "totalSum": totalSum,
      	                    "signedDate": signedDate,
      	                    "scheduleDate": scheduleDate,
      	                    "giveOutDate": giveOutDate,
      	                    "stop": stop,
      	                    "freightCharge": freightCharge,
      	                    "projectName": projectName,
      	                    "payType": payType,
      	                    "guaranteePeriod": guaranteePeriod,
      	                    "breakDuty": breakDuty,
      	                    "customerId": customerId,
      	                    "orderUnit": orderUnit,
      	                    "orderDelegate": orderDelegate,
      	                    "orderPhone": orderPhone,
      	                    "industryInfo": industryInfo,
      	                    "orderAddress": orderAddress,
      	                    "orderZip": orderZip,
      	                    "orderArea": orderArea,
      	                    "invoiceBank": invoiceBank,
	      	                "bankAccount": bankAccount,
	      	                "taxNumber": taxNumber,
	      	                "invoiceAddress": invoiceAddress,
      	                    "postUnit": postUnit,
      	                    "postDelegate": postDelegate,
      	                    "postPhone": postPhone,
      	                    "postAddress": postAddress,
      	                    "postZip": postZip,
      	                    "dutyArea": dutyArea,
      	                    "dutyOfficer": dutyOfficer,
      	                    "southNorthArea": southNorthArea,
      	                    "belongArea": belongArea,
      	                    "checkKind": checkKind,
      	                    "productKind": productKind,
      	                    "signOfficer": signOfficer,
      	                    "repairOfficer": repairOfficer,
      	                    "quotationOfficer": quotationOfficer,
      	                    "operatDepartment": operatDepartment,
      	                    "operator": operator,
      	                    "operatDate": operatDate,
      	                    "memo": memo,
      	                    "state": contractState,
      	                    "cstate": cstate,
      	            };
      	        }else{
      	        	var d = {
      	        			"id": isId,
      	        			"createTime": createTime,
      	        			"supplierCode": supplierCode,
      	                	"demanderCode": demanderCode,
      	                	"contractType": contractType,
      	                    "totalSum": totalSum,
      	                    "signedDate": signedDate,
      	                    "scheduleDate": scheduleDate,
      	                    "giveOutDate": giveOutDate,
      	                    "stop": stop,
      	                    "freightCharge": freightCharge,
      	                    "projectName": projectName,
      	                    "payType": payType,
      	                    "guaranteePeriod": guaranteePeriod,
      	                    "breakDuty": breakDuty,
      	                    "customerId": customerId,
      	                    "orderUnit": orderUnit,
      	                    "orderDelegate": orderDelegate,
      	                    "orderPhone": orderPhone,
      	                    "industryInfo": industryInfo,
      	                    "orderAddress": orderAddress,
      	                    "orderZip": orderZip,
      	                    "orderArea": orderArea,
      	                    "invoiceBank": invoiceBank,
	      	                "bankAccount": bankAccount,
	      	                "taxNumber": taxNumber,
	      	                "invoiceAddress": invoiceAddress,
      	                    "postUnit": postUnit,
      	                    "postDelegate": postDelegate,
      	                    "postPhone": postPhone,
      	                    "postAddress": postAddress,
      	                    "postZip": postZip,
      	                    "dutyArea": dutyArea,
      	                    "dutyOfficer": dutyOfficer,
      	                    "southNorthArea": southNorthArea,
      	                    "belongArea": belongArea,
      	                    "checkKind": checkKind,
      	                    "productKind": productKind,
      	                    "signOfficer": signOfficer,
      	                    "repairOfficer": repairOfficer,
      	                    "quotationOfficer": quotationOfficer,
      	                    "operatDepartment": operatDepartment,
      	                    "operator": operator,
      	                    "operatDate": operatDate,
      	                    "memo": memo,
      	                    "state": contractState,
      	                    "cstate": cstate,
      	            };
      	        }
      		}else if (contractType=="备件合同"){
      			var projectCode = jQuery('#projectCode').val();
      			var contract = "saveContractPart";
      			if(quoteId){
      				contract += "?quoteId="+quoteId;
      			}
      			// 判断是编辑还是新增
      	        if(isId == ""){// 新增合同
      	        	var d = {
      	        			"user":{"id":$("#userId").val()},
      	                	"supplierCode": supplierCode,
      	                	"demanderCode": demanderCode,
      	                	"contractType": contractType,
      	                    "totalSum": totalSum,
      	                    "signedDate": signedDate,
      	                    "scheduleDate": scheduleDate,
      	                    "giveOutDate": giveOutDate,
      	                    "projectCode": projectCode,
      	                    "stop": stop,
      	                    "freightCharge": freightCharge,
      	                    "projectName": projectName,
      	                    "payType": payType,
      	                    "guaranteePeriod": guaranteePeriod,
      	                    "breakDuty": breakDuty,
      	                    "customerId": customerId,
      	                    "orderUnit": orderUnit,
      	                    "orderDelegate": orderDelegate,
      	                    "orderPhone": orderPhone,
      	                    "industryInfo": industryInfo,
      	                    "orderAddress": orderAddress,
      	                    "orderZip": orderZip,
      	                    "orderArea": orderArea,
      	                    "invoiceBank": invoiceBank,
	      	                "bankAccount": bankAccount,
	      	                "taxNumber": taxNumber,
	      	                "invoiceAddress": invoiceAddress,
      	                    "postUnit": postUnit,
      	                    "postDelegate": postDelegate,
      	                    "postPhone": postPhone,
      	                    "postAddress": postAddress,
      	                    "postZip": postZip,
      	                    "dutyArea": dutyArea,
      	                    "dutyOfficer": dutyOfficer,
      	                    "southNorthArea": southNorthArea,
      	                    "belongArea": belongArea,
      	                    "checkKind": checkKind,
      	                    "productKind": productKind,
      	                    "signOfficer": signOfficer,
      	                    "repairOfficer": repairOfficer,
      	                    "quotationOfficer": quotationOfficer,
      	                    "operatDepartment": operatDepartment,
      	                    "operator": operator,
      	                    "operatDate": operatDate,
      	                    "memo": memo,
      	                    "state": contractState,
      	                    "cstate": cstate,
      	            };
      	        }else{
      	        	var d = {
      	        			"id": isId,
      	        			"createTime": createTime,
      	                	"supplierCode": supplierCode,
      	                	"demanderCode": demanderCode,
      	                	"contractType": contractType,
      	                    "totalSum": totalSum,
      	                    "signedDate": signedDate,
      	                    "scheduleDate": scheduleDate,
      	                    "giveOutDate": giveOutDate,
      	                    "projectCode": projectCode,
      	                    "stop": stop,
      	                    "freightCharge": freightCharge,
      	                    "projectName": projectName,
      	                    "payType": payType,
      	                    "guaranteePeriod": guaranteePeriod,
      	                    "breakDuty": breakDuty,
      	                    "customerId": customerId,
      	                    "orderUnit": orderUnit,
      	                    "orderDelegate": orderDelegate,
      	                    "orderPhone": orderPhone,
      	                    "industryInfo": industryInfo,
      	                    "orderAddress": orderAddress,
      	                    "orderZip": orderZip,
      	                    "orderArea": orderArea,
      	                    "invoiceBank": invoiceBank,
	      	                "bankAccount": bankAccount,
	      	                "taxNumber": taxNumber,
	      	                "invoiceAddress": invoiceAddress,
      	                    "postUnit": postUnit,
      	                    "postDelegate": postDelegate,
      	                    "postPhone": postPhone,
      	                    "postAddress": postAddress,
      	                    "postZip": postZip,
      	                    "dutyArea": dutyArea,
      	                    "dutyOfficer": dutyOfficer,
      	                    "southNorthArea": southNorthArea,
      	                    "belongArea": belongArea,
      	                    "checkKind": checkKind,
      	                    "productKind": productKind,
      	                    "signOfficer": signOfficer,
      	                    "repairOfficer": repairOfficer,
      	                    "quotationOfficer": quotationOfficer,
      	                    "operatDepartment": operatDepartment,
      	                    "operator": operator,
      	                    "operatDate": operatDate,
      	                    "memo": memo,
      	                    "state": contractState,
      	                    "cstate": cstate,
      	            };
      	        }
      		}else if (contractType=="备泵合同"){
      			var projectCode = jQuery('#projectCode').val();
      			var contract = "saveContractPump";
      			// 判断是编辑还是新增
      	        if(isId == ""){// 新增合同
      	        	var d = {
      	        			"user":{"id":$("#userId").val()},
      	                	"supplierCode": supplierCode,
      	                	"demanderCode": demanderCode,
      	                	"contractType": contractType,
      	                    "totalSum": totalSum,
      	                    "signedDate": signedDate,
      	                    "scheduleDate": scheduleDate,	
      	                    "giveOutDate": giveOutDate,
      	                    "projectCode": projectCode,
      	                    "stop": stop,
      	                    "freightCharge": freightCharge,
      	                    "projectName": projectName,
      	                    "payType": payType,
      	                    "guaranteePeriod": guaranteePeriod,
      	                    "breakDuty": breakDuty,
      	                    "customerId": customerId,
      	                    "orderUnit": orderUnit,
      	                    "orderDelegate": orderDelegate,
      	                    "orderPhone": orderPhone,
      	                    "industryInfo": industryInfo,
      	                    "orderAddress": orderAddress,
      	                    "orderZip": orderZip,
      	                    "orderArea": orderArea,
      	                    "invoiceBank": invoiceBank,
	      	                "bankAccount": bankAccount,
	      	                "taxNumber": taxNumber,
	      	                "invoiceAddress": invoiceAddress,
      	                    "postUnit": postUnit,
      	                    "postDelegate": postDelegate,
      	                    "postPhone": postPhone,
      	                    "postAddress": postAddress,
      	                    "postZip": postZip,
      	                    "dutyArea": dutyArea,
      	                    "dutyOfficer": dutyOfficer,
      	                    "southNorthArea": southNorthArea,
      	                    "belongArea": belongArea,
      	                    "checkKind": checkKind,
      	                    "productKind": productKind,
      	                    "signOfficer": signOfficer,
      	                    "repairOfficer": repairOfficer,
      	                    "quotationOfficer": quotationOfficer,
      	                    "operatDepartment": operatDepartment,
      	                    "operator": operator,
      	                    "operatDate": operatDate,
      	                    "memo": memo,
      	                    "state": contractState,
      	                    "cstate": cstate,
      	            };
      	        }else{
      	        	var d = {
      	        			"id": isId,
      	        			"createTime": createTime,
      	                	"supplierCode": supplierCode,
      	                	"demanderCode": demanderCode,
      	                	"contractType": contractType,
      	                    "totalSum": totalSum,
      	                    "signedDate": signedDate,
      	                    "scheduleDate": scheduleDate,
      	                    "giveOutDate": giveOutDate,
      	                    "projectCode": projectCode,
      	                    "stop": stop,
      	                    "freightCharge": freightCharge,
      	                    "projectName": projectName,
      	                    "payType": payType,
      	                    "guaranteePeriod": guaranteePeriod,
      	                    "breakDuty": breakDuty,
      	                    "customerId": customerId,
      	                    "orderUnit": orderUnit,
      	                    "orderDelegate": orderDelegate,
      	                    "orderPhone": orderPhone,
      	                    "industryInfo": industryInfo,
      	                    "orderAddress": orderAddress,
      	                    "orderZip": orderZip,
      	                    "orderArea": orderArea,
      	                    "invoiceBank": invoiceBank,
	      	                "bankAccount": bankAccount,
	      	                "taxNumber": taxNumber,
	      	                "invoiceAddress": invoiceAddress,
      	                    "postUnit": postUnit,
      	                    "postDelegate": postDelegate,
      	                    "postPhone": postPhone,
      	                    "postAddress": postAddress,
      	                    "postZip": postZip,
      	                    "dutyArea": dutyArea,
      	                    "dutyOfficer": dutyOfficer,
      	                    "southNorthArea": southNorthArea,
      	                    "belongArea": belongArea,
      	                    "checkKind": checkKind,
      	                    "productKind": productKind,
      	                    "signOfficer": signOfficer,
      	                    "repairOfficer": repairOfficer,
      	                    "quotationOfficer": quotationOfficer,
      	                    "operatDepartment": operatDepartment,
      	                    "operator": operator,
      	                    "operatDate": operatDate,
      	                    "memo": memo,
      	                    "state": contractState,
      	                    "cstate": cstate,
      	            };
      	        }
      		}else if (contractType=="维修合同"){
      			var repairDate = jQuery('#repairDate').val();
      			if (repairDate==""){
      				message("请将返厂日期信息完善，保存后还可进行编辑。");
      		 		return ;
      	 		}
      				var projectCode = jQuery('#projectCode').val();
      				var repairCode = jQuery('#repairCode').val();
      				var repairNumber = jQuery('#repairNumber').val();
      				var repairKind = jQuery('#repairKind').val();
      			var contract = "saveContractRepair";
      			// 判断是编辑还是新增
      	        if(isId == ""){// 新增合同
      	        	var d = {
      	        			"user":{"id":$("#userId").val()},
      	                	"supplierCode": supplierCode,
      	                	"demanderCode": demanderCode,
      	                	"contractType": contractType,
      	                    "totalSum": totalSum,
      	                    "signedDate": signedDate,
      	                    "scheduleDate": scheduleDate,
      	                    "giveOutDate": giveOutDate,
      	                    "projectCode": projectCode,
      	                    "repairCode": repairCode,
      	                    "repairNumber": repairNumber,
      	                    "repairKind": repairKind,
      	                    "repairDate": repairDate,
      	                    "stop": stop,
      	                    "freightCharge": freightCharge,
      	                    "projectName": projectName,
      	                    "payType": payType,
      	                    "guaranteePeriod": guaranteePeriod,
      	                    "breakDuty": breakDuty,
      	                    "customerId": customerId,
      	                    "orderUnit": orderUnit,
      	                    "orderDelegate": orderDelegate,
      	                    "orderPhone": orderPhone,
      	                    "industryInfo": industryInfo,
      	                    "orderAddress": orderAddress,
      	                    "orderZip": orderZip,
      	                    "orderArea": orderArea,
      	                    "invoiceBank": invoiceBank,
	      	                "bankAccount": bankAccount,
	      	                "taxNumber": taxNumber,
	      	                "invoiceAddress": invoiceAddress,
      	                    "postUnit": postUnit,
      	                    "postDelegate": postDelegate,
      	                    "postPhone": postPhone,
      	                    "postAddress": postAddress,
      	                    "postZip": postZip,
      	                    "dutyArea": dutyArea,
      	                    "dutyOfficer": dutyOfficer,
      	                    "southNorthArea": southNorthArea,
      	                    "belongArea": belongArea,
      	                    "checkKind": checkKind,
      	                    "productKind": productKind,
      	                    "signOfficer": signOfficer,
      	                    "repairOfficer": repairOfficer,
      	                    "quotationOfficer": quotationOfficer,
      	                    "operatDepartment": operatDepartment,
      	                    "operator": operator,
      	                    "operatDate": operatDate,
      	                    "memo": memo,
      	                    "state": contractState,
      	                    "cstate": cstate,
      	            };
      	        }else{
      	        	var d = {
      	        			"id": isId,
      	        			"createTime": createTime,
      	                	"supplierCode": supplierCode,
      	                	"demanderCode": demanderCode,
      	                	"contractType": contractType,
      	                    "totalSum": totalSum,
      	                    "signedDate": signedDate,
      	                    "scheduleDate": scheduleDate,
      	                    "giveOutDate": giveOutDate,
      	                    "projectCode": projectCode,
      	                    "repairCode": repairCode,
      	                    "repairNumber": repairNumber,
      	                    "repairKind": repairKind,
      	                    "repairDate": repairDate,
      	                    "stop": stop,
      	                    "freightCharge": freightCharge,
      	                    "projectName": projectName,
      	                    "payType": payType,
      	                    "guaranteePeriod": guaranteePeriod,
      	                    "breakDuty": breakDuty,
      	                    "customerId": customerId,
      	                    "orderUnit": orderUnit,
      	                    "orderDelegate": orderDelegate,
      	                    "orderPhone": orderPhone,
      	                    "industryInfo": industryInfo,
      	                    "orderAddress": orderAddress,
      	                    "orderZip": orderZip,
      	                    "orderArea": orderArea,
      	                    "invoiceBank": invoiceBank,
	      	                "bankAccount": bankAccount,
	      	                "taxNumber": taxNumber,
	      	                "invoiceAddress": invoiceAddress,
      	                    "postUnit": postUnit,
      	                    "postDelegate": postDelegate,
      	                    "postPhone": postPhone,
      	                    "postAddress": postAddress,
      	                    "postZip": postZip,
      	                    "dutyArea": dutyArea,
      	                    "dutyOfficer": dutyOfficer,
      	                    "southNorthArea": southNorthArea,
      	                    "belongArea": belongArea,
      	                    "checkKind": checkKind,
      	                    "productKind": productKind,
      	                    "signOfficer": signOfficer,
      	                    "repairOfficer": repairOfficer,
      	                    "quotationOfficer": quotationOfficer,
      	                    "operatDepartment": operatDepartment,
      	                    "operator": operator,
      	                    "operatDate": operatDate,
      	                    "memo": memo,
      	                    "state": contractState,
      	                    "cstate": cstate,
      	            };
      	        }
      		}
      		jQuery(".btnUpload").attr("disabled", true);
      		jQuery(".saveContractBtn").attr("disabled", true);
      		jQuery(".submitBtn").attr("disabled", true);
      		jQuery(".app-btn-submit").attr("disabled", true);
      		var id=isId;
      		if (id==null||id==''){
      			id = 'null';
      		}
      		if (supplierCode!=''){// 验证供方合同号是否已存在
      			
      			var urlValid=window.rootPath+"/ui/contract/validSupplierCode/"+id+"/"+supplierCode;
      	    	jQuery.ajax({
      	            url:encodeURI(urlValid),
      	            cache:false,
      	            type :"get",
      	            dataType:"json",
      	            contentType:"application/json;charset=utf-8",// 解决返回数据中的中文乱码问题
      	            success:function(data){
      	            	if(data.codeState==1){
      	            		$.springLemonDialog({
      	  					content : '供方合同号已存在，请修改！',// 确认文本
      	  					clickButton : function(sender, modal, index) {// 按钮事件处理
      	  						$(this).closeDialog(modal);
      	  					}
      	            		});
      	            		jQuery(".btnUpload").attr("disabled", false);
      	            		jQuery(".saveContractBtn").attr("disabled", false);
      	            		jQuery(".submitBtn").attr("disabled", false);
      	            		jQuery(".app-btn-submit").attr("disabled", false);
      	            		return;
      	            	}
      	            	if(contractType=="项目合同"){
      	            		if (totalSum==""){
          	            		totalSum = 0;
          	            	}
          	            	var url0=window.rootPath+"/ui/contract/validTotalSum/"+id+"/"+totalSum+"/0";
          	         		jQuery.ajax({
          	      	            url:encodeURI(url0),
          	      	            cache:false,
          	      	            type :"get",
          	      	            dataType:"json",
          	      	            contentType:"application/json;charset=utf-8",// 解决返回数据中的中文乱码问题
          	      	            success:function(data){
          	      	            	if(data.sumState==1){
          	      	            		$.springLemonDialog({
          	      	  					content : '合同总价小于占比划分总金额，请修改！',// 确认文本
          	      	  					clickButton : function(sender, modal, index) {// 按钮事件处理
          	      	  						$(this).closeDialog(modal);
          	      	  					}
          	      	            		});
	          	      	            	jQuery(".btnUpload").attr("disabled", false);
	      	                        	jQuery(".saveContractBtn").attr("disabled", false);
	      	                    		jQuery(".submitBtn").attr("disabled", false);
	      	                    		jQuery(".app-btn-submit").attr("disabled", false);
          	      	            		return;
          	      	            	}
          	      	            var url = window.rootPath + "/ui/contract/" + contract;
          	                    jQuery.ajax({
          	                        type: 'post',
          	                        url : encodeURI(url),
          	                        data: JSON.stringify(d),
          	                        dataType: 'json',
          	                        contentType: 'application/json;charset=utf-8',
          	                        success: function (data) {
          	                        	var contractId = data.contractId;
          	                        	var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss")
          	                        	jQuery("#createTime").val(time);
          	                        	jQuery("#contractId").val(contractId);
          	                        	jQuery(".btnUpload").attr("disabled", false);
          	                        	jQuery(".saveContractBtn").attr("disabled", false);
          	                    		jQuery(".submitBtn").attr("disabled", false);
          	                    		jQuery(".app-btn-submit").attr("disabled", false);
          	                        	if (state=="submitBtn"){
          	                        		showAuditTable();
          	                        	}else if (state=="saveContractBtn"){
          	                        		window.location.href = window.rootPath+'/ui/contract/';
          	                        	}else if (state=="btnUpload"){
          	                        		var goupId = "方案附件";
          	                        		fileUpload(contractId,goupId);
          	                        	}
          	                        	
          	                        	//
          	      	                	var url = window.rootPath + "/ui/contract/getDivideScale?contractId="+jQuery("#contractId").val();
          	      	          		jQuery.ajax({
          	      	                        type: 'get',
          	      	                        serverSide:true,
          	      	                        ordering:false,
          	      	                        url : encodeURI(url),
          	      	                        data: JSON.stringify(),
          	      	                        dataType: 'json',
          	      	                        contentType: 'application/json;charset=utf-8',
          	      	                        success: function (data) {
          	      	                        	if(data.data.length != 0){
          	      	                        		return;
          	      	                        	}else{
          	      	                        		var functionary = jQuery("#dutyOfficer").val();
          	      	                        		var belongArea = jQuery("#orderArea").val();
          	      	                        		var scaleDivide = jQuery("#totalSum").val();
          	      	                        		var percent = 100;
          	      	                        		var api = window.rootPath + "/api/divideScales";
          	      	          	                var d = {
          	      	          	                		"contractID": contractId,
          	      	          	                        "functionary": functionary,
          	      	          	                        "belongArea": belongArea,
          	      	          	                        "scaleDivide": scaleDivide,
          	      	          	                        "percent": percent
          	      	          	                };
          	      	          	                jQuery.ajax({
          	      	          	                    type: 'post',
          	      	          	                    url: api,
          	      	          	                    data: JSON.stringify(d),
          	      	          	                    dataType: 'json',
          	      	          	                    contentType: 'application/json;charset=utf-8',
          	      	          	                    success: function (data) {
          	      	          	                    	jQuery('#divideScaleModal').modal('hide');
          	      	          	                    	divideScaleData.contractId=jQuery('#contractId').val();
          	      	          	                    	serverScaleTable.draw(true);
          	      	          	                    	var operateType = "新增合同占比划分";
          	      	          	                    	var content = "新增【项目合同】【"+supplierCode+"】占比划分负责人【"+functionary+"】";
          	      	          	                		jQuery(".addScaleBtn").attr("disabled", false);
          	      	                	            		jQuery(".saveScaleBtn").attr("disabled", false);
          	      	          	                    }
          	      	          	                });
          	      	                        	}
          	      	                        }
          	      	                    });
          	      	                	//
          	                        }
          	                    });
          	      	            }
          	         		})
      	            	}else{
      	            		var url = window.rootPath + "/ui/contract/" + contract;
      	                    jQuery.ajax({
      	                        type: 'post',
      	                        url : encodeURI(url),
      	                        data: JSON.stringify(d),
      	                        dataType: 'json',
      	                        contentType: 'application/json;charset=utf-8',
      	                        success: function (data) {
      	                        	var contractId = data.contractId;
      	                        	var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss")
      	                        	jQuery("#createTime").val(time);
      	                        	jQuery("#contractId").val(contractId);
      	                        	jQuery(".btnUpload").attr("disabled", false);
      	                        	jQuery(".saveContractBtn").attr("disabled", false);
      	                    		jQuery(".submitBtn").attr("disabled", false);
      	                    		jQuery(".app-btn-submit").attr("disabled", false);
      	                        	if (state=="submitBtn"){
      	                        		showAuditTable();
      	                        	}else if (state=="saveContractBtn"){
      	                        		window.location.href = window.rootPath+'/ui/contract/';
      	                        	}else if (state=="btnUpload"){
      	                        		var goupId = "方案附件";
      	                        		fileUpload(contractId,goupId);
      	                        	}else if(state=="importQuote"){
      	                        		var replaceTables = $('#resultReplacementTable').DataTable();
      	                        		replaceTables.settings()[0].ajax.data = {"contractId":contractId};
      	                        		replaceTables.ajax.reload();
      	                        		jQuery("#quotation-dialog").modal("hide")
      	                        	}
      	                        }
      	                    });
      	            	}
      	            }
      	    	});
      		}else{
      			if(contractType=="项目合同"){
	            		if (totalSum==""){
  	            		totalSum = 0;
  	            	}
  	            	var url0=window.rootPath+"/ui/contract/validTotalSum/"+id+"/"+totalSum+"/0";
  	         		jQuery.ajax({
  	      	            url:encodeURI(url0),
  	      	            cache:false,
  	      	            type :"get",
  	      	            dataType:"json",
  	      	            contentType:"application/json;charset=utf-8",// 解决返回数据中的中文乱码问题
  	      	            success:function(data){
  	      	            	if(data.sumState==1){
  	      	            		$.springLemonDialog({
  	      	  					content : '合同总价小于占比划分总金额，请修改！',// 确认文本
  	      	  					clickButton : function(sender, modal, index) {// 按钮事件处理
  	      	  						$(this).closeDialog(modal);
  	      	  					}
  	      	            		});
  	      	            		jQuery(".btnUpload").attr("disabled", false);
	                        	jQuery(".saveContractBtn").attr("disabled", false);
	                    		jQuery(".submitBtn").attr("disabled", false);
	                    		jQuery(".app-btn-submit").attr("disabled", false);
  	      	            		return;
  	      	            	}
  	      	            var url = window.rootPath + "/ui/contract/" + contract;
  	      	            jQuery.ajax({
  	      	                type: 'post',
  	      	                url : encodeURI(url),
  	      	                data: JSON.stringify(d),
  	      	                dataType: 'json',
  	      	                contentType: 'application/json;charset=utf-8',
  	      	                success: function (data) {
  	      	                	var contractId = data.contractId;
  	      	                	var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss")
  	      	                	jQuery("#createTime").val(time);
  	      	                	jQuery("#contractId").val(contractId);
  	      	                	jQuery(".btnUpload").attr("disabled", false);
  	      	                	jQuery(".saveContractBtn").attr("disabled", false);
  	      	            		jQuery(".submitBtn").attr("disabled", false);
  	      	            		jQuery(".app-btn-submit").attr("disabled", false);
  	      	                	if (state=="submitBtn"){
  	      	                		showAuditTable();
  		                    	}else if (state=="saveContractBtn"){
  		                    		window.location.href = window.rootPath+'/ui/contract/';
  		                    	}else if (state=="btnUpload"){
  	  	                        	var goupId = "方案附件";
  	  	                       		fileUpload(contractId,goupId);
  	  	                       	}
  	      	                }
  	      	            });
  	      	            }
  	         		})
      			}else{
      				var url = window.rootPath + "/ui/contract/" + contract;
      	            jQuery.ajax({
      	                type: 'post',
      	                url : encodeURI(url),
      	                data: JSON.stringify(d),
      	                dataType: 'json',
      	                contentType: 'application/json;charset=utf-8',
      	                success: function (data) {
      	                	var contractId = data.contractId;
      	                	var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss")
      	                	jQuery("#createTime").val(time);
      	                	jQuery("#contractId").val(contractId);
      	                	jQuery(".btnUpload").attr("disabled", false);
      	                	jQuery(".saveContractBtn").attr("disabled", false);
      	            		jQuery(".submitBtn").attr("disabled", false);
      	            		jQuery(".app-btn-submit").attr("disabled", false);
      	                	if (state=="submitBtn"){
      	                		showAuditTable();
	                    	}else if (state=="saveContractBtn"){
	                    		window.location.href = window.rootPath+'/ui/contract/';
	                    	}else if (state=="btnUpload"){
  	                        	var goupId = "方案附件";
  	                       		fileUpload(contractId,goupId);
  	                       	}else if(state=="importQuote"){
  	                       	var replaceTables = $('#resultReplacementTable').DataTable();
                      		replaceTables.settings()[0].ajax.data = {"contractId":contractId};
                      		replaceTables.ajax.reload();
                      		jQuery("#quotation-dialog").modal("hide")
  	                        	}
      	                }
      	            });
      			}
      		}
      	};
      	
      	/**
      	 * 显示审批选项
      	 */
      	var showAuditTable = function() {
      		document.getElementById("auditTable").style.display='block';
	        document.getElementById("submitBtn").style.display='none';
	        document.getElementById("saveContractBtn").style.display='none';
	        document.getElementById("app-btn-submit").style.display='block';
      	}
        
      	// 默认显示第一个tab页
        $('#myTabs a:first').tab('show'); 
        
        // 合同列表中的全选
        $(document).on("click","#checkAllContract",function(){
        	var check = $(this).prop("checked");
            $(".checkchildContract").prop("checked", check);
    	});
        $(document).on("click",".checkchildContract",function(){
        	var check=$(this).prop("checked");
        	var index=$(this).parent().parent().attr("data-dt-row");
        	jQuery(".dataTables_scrollBody .checkchildContract").eq(index).prop("checked", check);
        })
        // 合同关键点列表中的全选
        $("#checkAllCruxDate").click(function(){
        	var check = $(this).prop("checked");
            $(".checkchildCruxDate").prop("checked", check);
    	});
        
        ///下拉框行业信息改变,将其值赋给所属板块////
		jQuery('#industryInfo').trigger('change');///自动触发下拉框
		
		jQuery('#industryInfo').change(function(){
			jQuery("#belongArea").val(jQuery("#industryInfo").val());
		});
		
		///excel导出
		jQuery('.import').on("click",function() {
			var selects=getSelect("#dataTable",1);
			if(selects.length>0){
				var key=selects[0].contractId;
				for(var i=1;i<selects.length;i++){

					   key += ',' + selects[i].contractId;  
				 }
				   var url=window.rootPath+ "/ui/contract/exportSelects/"+key;
				   window.location = url;
				
			}else{
				getServerDate();
				var d={};
				d=serverData;
				var url = window.rootPath+ "/ui/contract/exportByKey";
				jQuery.ajax({
        			url:  encodeURI(url),
        			type: 'get',
        			data:d,
        			dataType: 'json',
        			success:function(data){
        				var contracts=data.contracts;
						if(contracts){
							var key=contracts[0].contractId;
							for(var n=1;n<contracts.length;n++){
								 key += ',' + contracts[n].contractId;
							}
							var url=window.rootPath+ "/ui/contract/exportSelects/"+key;
							window.location = url;
						}else{
							message("没有找到匹配合同可供导出")
						}
					}
				});
			}
			
		});
		
		///excel导出所有合同
		jQuery('.importAll').on("click",function() {
		   var url=window.rootPath+ "/ui/contract/exportSelectsAll";
		   window.location = url;
		});
		
		//人员选择下拉框采用select2
		jQuery("#dutyArea").select2().trigger("change");
	 	jQuery("#dutyOfficer").select2().trigger("change");
   	 	jQuery("#signOfficer").select2().trigger("change");
	 	jQuery("#repairOfficer").select2().trigger("change");
	 	jQuery("#quotationOfficer").select2().trigger("change");
	 	
	 	
	 	
	 	
	 	
	    //引入报价单按钮importQuote
	    jQuery("#importQuote").on('click',function() {
	    	if(
	    	    	!jQuery("#supplierCode").val()||
	    	    	!jQuery("#projectName").val()||
	    	    	!jQuery("#giveOutDate").val()||
	    	    	!jQuery("#orderArea").val()||
	    	    	!jQuery("#payType").val()||
	    	    	!jQuery("#totalSum").val()||
	    	    	!jQuery("#industryInfo").val()||
	    	    	!jQuery("#signedDate").val()
	    	    	){
	    	    		message("请先完善供方合同号、总价、签订日期、付款方式、订货片区")
	    	    		return;
	    	    	}
	    	jQuery("#quotation-dialog").modal("show")
//	    	if(
//	    	!jQuery("#supplierCode").val()||
//	    	!jQuery("#breakDuty").val()||
//	    	!jQuery("#guaranteePeriod").val()||
//	    	!jQuery("#payType").val()||
//	    	!jQuery("#totalSum").val()||
//	    	!jQuery("#signedDate").val()
//	    	){
//	    		message("请先完善供方合同号、总价、签订日期、付款方式、质保期限、违约责任")
//	    		return;
//	    	}
	    	
	    })
	    jQuery("#adjustment").on('click',function() {
	    	var totalSum = jQuery("#totalSum").val();
	    	if(parseFloat(totalSum) > 0){
	    		jQuery("#oldtotalSum").val(totalSum);
	    		jQuery("#adjustmentModal").modal("show");
	    	}else{
	    		alert("请输入合同总价！");
	    	}
	    });
	    jQuery("#up").on('click',function() {
	    	var oldtotalSum = jQuery("#oldtotalSum").val();
	    	var ratio = jQuery("#ratio").val();
	    	var contractId = jQuery("#contractId").val();
	    	var newtotalSum = (100 + parseFloat(ratio))/100 * oldtotalSum;
	    	if(contractId == ""){
	    		message("请先保存备件合同基本信息。");
	    		jQuery("#adjustmentModal").modal("hide");
	    		return;
	    	}
	    	upordown(ratio);
	    	jQuery("#totalSum").val(newtotalSum);
	    	jQuery("#adjustmentModal").modal("hide");
	    });
	    jQuery("#down").on('click',function() {
	    	var oldtotalSum = jQuery("#oldtotalSum").val();
	    	var ratio = jQuery("#ratio").val();
	    	var contractId = jQuery("#contractId").val();
	    	var newtotalSum = (100 - parseFloat(ratio))/100 * oldtotalSum;
	    	if(contractId == ""){
	    		message("请先保存备件合同基本信息。");
	    		jQuery("#adjustmentModal").modal("hide");
	    		return;
	    	}
	    	upordown("-"+ratio);
	    	jQuery("#totalSum").val(newtotalSum);
	    	jQuery("#adjustmentModal").modal("hide");
	    });
	    var upordown = function(ratio){
	    	var contractId = jQuery("#contractId").val();
	    	
	    	var api=window.rootPath+"/ui/contract/upordown?contractId="+contractId + "&ratio=" + ratio;
	    	jQuery.ajax({
				type: 'get',
	            url:  encodeURI(api),
	            dataType: 'json',
	            contentType: 'application/json;charset=utf-8',
				success : function(res) {
					contractReplacementData.contractId = contractId;
					serverReplacementTable.draw();
					}
				})
	    }
	    
	    var contractReplacementData = {};
	    contractReplacementData.contractId = jQuery("#contractId").val();
	    var serverReplacementTable = jQuery('#resultReplacementTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "iDisplayLength":9999,
            "page":false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/contract/getReplacement',
                "data": function (d) {
                    return $.extend({}, d, contractReplacementData);
                }
            },
            columns: [
                {
                	data: 'indexOrder'
                },
                {
    	            data: null,
    	            defaultContent: "",
    	            render: function (data, type, full, meta) {
    	            	var id=data.id
    	            	var operate ='<input type="checkbox" class="checkchildReplacement">';
    	            	return operate;
    	            }   
                },
                {
                    data: 'supplierCode'
                },
                {
                    data: 'deviceName'
                },
                {
                    data: 'type'
                },
                {
                	data: 'material'
                },
                {
                	data: 'unit'
                },
                {
                    data: 'amount'
                },
                {
                    data: 'nOneDiscount'
                },
                {
                    data: 'price'
                },
                {
                	 data: 'materialCoding'
                },
                {
                	data: 'branchFactory'
                },
                {
                	data: 'cusMaterielName'
                },
                {
                	data: 'cusMaterielSpec'
                },
                {
                	 data: 'memo',
                	 render:function(data,type,full,meta){
 							return '<font title="'+data+'">'+stringCut(data,12)+'</font>'
 					}
                }
                ],
            "drawCallback": function (oSettings) {
//                var k = 0;
//                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
//
//                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
//                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
//                    k++;
//                }
                var data=oSettings.json.data;
                var total=0;
                for(var i=0;i<data.length;i++){
                	total+=data[i].price;
                }
                var tds="<tr><td  colspan='2'>含税总金额(元)</td>"
							+"<td colspan='11' >"+total+"</td>" 
						+"</tr>";
                jQuery("#resultReplacementTable tbody").append(tds);
                
            }
        });
	    
	    //引入报价单按钮btn-quotation
	    jQuery("#btn-quotation").on('click',function() {
	    	var selects=getSelect("#table-quotation",1);
	    	if(selects.length==1){
	    		
	    
	    		jQuery("#projectName").val(selects[0].name);
	    		jQuery("#giveOutDate").val(moment(selects[0].deliveryDate).format('YYYY-MM-DD'));
	    		
	    		var quoteId=selects[0].id;
	    		var customerId=selects[0].customerId
	    		var api=window.rootPath+"/ui/customer/getCustomer?customerId="+customerId
	    		jQuery.ajax({
					type: 'get',
		            url:  encodeURI(api),
		            dataType: 'json',
		            contentType: 'application/json;charset=utf-8',
					success : function(res) {
						var customer=res.customer;
						jQuery("#orderUnit").val(customer.customerName);
					   	jQuery("#orderZip").val(customer.zipCode);
//					   	var orderArea = customer.saleArea.superior+"-"+customer.saleArea.areaName;
					   	var oldorderArea = jQuery("#orderArea").val();
					   	jQuery("#orderArea").val(customer.saleArea.superiorArea);
					   	jQuery("#orderArea").select2().trigger("change");
					   	var neworderArea = jQuery("#orderArea").val();
					   	if(neworderArea == "" || neworderArea == null){
					   		jQuery("#orderArea").val(oldorderArea);
						   	jQuery("#orderArea").select2().trigger("change");
					   	}
					   	var oldindustryInfo = jQuery("#industryInfo").val();
					   	jQuery("#industryInfo").val(customer.industryInfo);
					   	var newindustryInfo = jQuery("#industryInfo").val();
					   	if(newindustryInfo == "" || newindustryInfo == null){
					   		jQuery("#industryInfo").val(oldindustryInfo);
						   	jQuery("#industryInfo").select2().trigger("change");
					   	}
					   	//jQuery("#industryInfo").val(customer.business);
					   	jQuery("#belongArea").val(customer.business);//合同分类明细的所属板块也就是行业信息
					   	jQuery("#orderAddress").val(customer.address);
					   	jQuery("#invoiceBank").val(customer.invoiceBank);
					   	jQuery("#bankAccount").val(customer.bankAccount);
					   	jQuery("#taxNumber").val(customer.taxNumber);
					   	jQuery("#invoiceAddress").val(customer.invoiceAddress);
					   	jQuery("#postUnit").val(customer.postUnit);
					   	jQuery("#postDelegate").val(customer.postDelegate);
					   	jQuery("#postPhone").val(customer.postPhone);
					   	jQuery("#postAddress").val(customer.postAddress);
					   	jQuery("#postZip").val(customer.postZip);
			   	   		jQuery("#customerId").val(customer.id);
			   	   		jQuery("#orderDelegate").val(customer.cDHDB);
			   	   		jQuery("#orderPhone").val(customer.cDHPhone);
			   	   		jQuery("#query-Customer-Modal").modal('hide');
			   	   		var url=window.rootPath + "/ui/customer/getDefaultInfo?customerId="+customer.id+"&hostType="+(jQuery("#contractType").val()=="项目合同"?1:0);
		   				jQuery.ajax({
			   					type: 'get',
					            url:  encodeURI(url),
					            data: JSON.stringify(""),
					            dataType: 'json',
					            contentType: 'application/json;charset=utf-8',
			   					success : function(data) {
			   						if(data.data[0]!=null){
			   		   	   			   	jQuery("#orderZip").val(data.data[0].zipCode);
			   		   	   			   	jQuery("#postZip").val(data.data[0].zipCode);
			   		   	   			   	jQuery("#postPhone").val(data.data[0].invoicePhone);
			   		   	   			   	jQuery("#orderPhone").val(data.data[0].invoicePhone);
			   		   	   			   	jQuery("#postAddress").val(data.data[0].invoiceAddress);
			   		   	   			   	jQuery("#invoiceAddress").val(data.data[0].invoiceAddress);
			   		   	   			   	jQuery("#orderAddress").val(data.data[0].invoiceAddress);
			   		   	   			   	jQuery("#invoiceBank").val(data.data[0].invoiceBank);
			   		   	   			   	jQuery("#bankAccount").val(data.data[0].bankAccount);
			   		   	   			   	jQuery("#taxNumber").val(data.data[0].taxNumber);
			   						}
			   						if(data.data[1]!=null){
			   		   	   			   	jQuery("#postUnit").val(data.data[1].postUnit);
			   		   	   			   	jQuery("#postDelegate").val(data.data[1].postDelegate);
			   		   	   			   	jQuery("#postPhone").val(data.data[1].postPhone);
			   		   	   			   	jQuery("#postAddress").val(data.data[1].postAddress);
			   		   	   			   	jQuery("#postZip").val(data.data[1].postZip);
			   						}
			   						
			   						saveContract1("importQuote",quoteId);
			   					}
		   				});
					}
	    		});
	    	}else if(selects.length>1){
	    		message('单条引入');
	    	}
	    	
	    })
	    var serverTable6;
	    var serverData6={};
	    serverData6.key="";
	  //报价单
		serverTable6 = jQuery('#table-quotation').DataTable({
			"serverSide" : true,
			"ordering" : false,
			"ajax" : {
				"dataType" : "json",
				"type" : "post",
				"cache" : false,
				"url" : window.rootPath
				+ '/ui/beforecontract/quotesearch/getpumgpage',
				"data" : function(d) {
					return $.extend({}, d,
							serverData6);
				}
			},
			columns : [
			           {
			        	   data : null,
			        	   defaultContent : ""
			           },
			           {
			        	   data : null,
			        	   defaultContent : "",
			        	   render : function(data,
			        			   type, full, meta) {
			        		   var id = data.id
			        		   var operate = '<input type="checkbox" class="checkchild">';
			        		   return operate;
			        		   
			        	   }
			           },
			           {
			        	   data: 'name'
			           },
			           {
			        	   data:'customerName'
			           },
			           
			           {
			        	   data: 'sum'
			           },
			           {
			        	   data: 'memo'
			           }
			           ],
			           "drawCallback": function (oSettings) {
			        	   var k = 0;
			        	   var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
			        	   for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
			        		   $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
			        		   k++;
			        	   }
			        	   
			           }
		});
	    
		jQuery('#btn-quotationSearch').on('click', function() {
			serverData6.key = jQuery("#quotation-search").val();
			serverTable6.draw();
		});
	  	jQuery('#btn-quotationReset').on('click', function() {
	  		jQuery("#quotation-search").val("");
	  		serverData6.key = "";
	  		serverTable6.draw();
	  	});
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
    });///document。ready
    
  // 以下为审批相关内容
	 
    /*// 发起审批
    jQuery(".app-btn-audit").on('click',function(){
   	 var selects=getSelect("#dataTable",1);
   	 if(selects.length>1){
   		   $.springLemonDialog({
   		         content: '一次只能对一条记录发起审批',// 确认文本
   		         clickButton: function (sender, modal, index) {// 按钮事件处理
   		             $(this).closeDialog(modal);
   		         }
   		   }); 
   	   }
   	   else if(selects.length==0){
   		   $.springLemonDialog({
   		         content: '请选择要发起审批的记录',// 确认文本
   		         clickButton: function (sender, modal, index) {// 按钮事件处理
   		             $(this).closeDialog(modal);
   		         }
   		   }); 
   	   }else if(selects.length==1){
   		  if(selects[0].auditState=='通过'){
   			$.springLemonDialog({
  					content : selects[0].supplierCode+'已经审批通过',// 确认文本
  					clickButton : function(sender, modal, index) {// 按钮事件处理
  						$(this).closeDialog(modal);
  					}
            		});
   				return;
   			}
   		  if(selects[0].auditState=='已提交'  || selects[0].auditState=='审批中' ){
   			$.springLemonDialog({
					content : selects[0].supplierCode+'已经提交审批',// 确认文本
					clickButton : function(sender, modal, index) {// 按钮事件处理
						$(this).closeDialog(modal);
					}
        		});
   				return;
   			}
   		 var contractId=selects[0].contractId;
   		 var contractType=selects[0].contractType;
         var contractCode=selects[0].supplierCode;
   		 var url=window.rootPath+'/ui/contract/audit/'+ contractId +'/'+ contractType;
  
	 * jQuery.get(url,{ "contractId":contractId, "contractType":contractType,
	 * "contractCode":contractCode
	 * 
	 * });
	 
   		window.location = url;
   	   }
   });*/
 // 引入签订前要点审批按钮
    $("#savehq").click(function(){
    	jQuery('#modal-find-qdqydsp').modal("show");
    	serverTable2 = jQuery('#table-qdqydsp').DataTable({
            "serverSide" : true,
            "ordering" : false,
            "ajax" : {
                "dataType" : "json",
                "type" : "post",
                "cache" : false,
                "url" : window.rootPath + '/ui/beforecontract/getpage',
                "data" : function(d) {
                    return $.extend({}, d,
                            serverData2);
                }
            },
            "columns" : [{
                            data : null,
                            defaultContent : ""// 排序   1
                        },
                        {
            	            data: null,
            	            defaultContent: "",
            	            render: function (data, type, full, meta) {
            	            	var id=data.id
            	            	var operate ='<input type="checkbox" class="checkchildContract">';
            	            	return operate;
            	            }   
                        },
                        {
                            data : 'cContractCode'//合同号,
        		                ,render:function(data,type,full,meta){
        		                	if(data == null || data == undefined || data == ""){
        								return data;
        							}else{
        								return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
        							}
        						}
                        },
                        {
                            data : 'nContractPrice'//合同总价
                        },
                        {
                            data : 'cProjectName'//项目名称,
        		                ,render:function(data,type,full,meta){
        		                	if(data == null || data == undefined || data == ""){
        								return data;
        							}else{
        								return (data.length > 6) ? '<font title="'+data+'">'+data.substring(0,6)+'...'+'</font>' : data;
        							}
        						}
                        },
                        {
                            data : 'dPlanSignDate',//预计签订日期
                            render: function (data, type, full, meta) {
                                if (data)
                                    return moment(data).format('YYYY/MM/DD HH:mm');
                                else
                                    return '';
                            }
                        },
                        {
                            data : 'cQualityMemo'//质保期
                            	,
        		                render:function(data,type,full,meta){
        		                	if(data == null || data == undefined || data == ""){
        								return data;
        							}else{
        								return (data.length > 7) ? '<font title="'+data+'">'+data.substring(0,7)+'...'+'</font>' : data;
        							}
        						}
                        },
                        {
                            data : 'cPayWayMemo'//付款方式
                            	,
        		                render:function(data,type,full,meta){
        		                	if(data == null || data == undefined || data == ""){
        								return data;
        							}else{
        								return (data.length > 7) ? '<font title="'+data+'">'+data.substring(0,7)+'...'+'</font>' : data;
        							}
        						}
                        },
                        {
                            data : 'cLiabilityMemo'//违约责任
                            	,
        		                render:function(data,type,full,meta){
        		                	if(data == null || data == undefined || data == ""){
        								return data;
        							}else{
        								return (data.length > 7) ? '<font title="'+data+'">'+data.substring(0,7)+'...'+'</font>' : data;
        							}
        						}
                        
                        }],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
	});
   	 //签订前要点审批弹窗中的引入按钮
    $("#btn-reference15").click(function(){
    	var selects=getSelect("#table-qdqydsp",1);
    	if(selects.length==0){
 		   $.springLemonDialog({
 		         content: '请选择要数据',// 确认文本
 		         clickButton: function (sender, modal, index) {// 按钮事件处理
 		             $(this).closeDialog(modal);
 		         }
 		   }); 
		}else if(selects.length>1){
 		   $.springLemonDialog({
 		         content: '一次只能选择一条数据',// 确认文本
 		         clickButton: function (sender, modal, index) {// 按钮事件处理
 		             $(this).closeDialog(modal);
 		         }
 		   }); 
		}else{
			jQuery("#supplierCode").val(selects[0].cContractCode);
			jQuery("#totalSum").val(selects[0].nContractPrice);
			var a = selects[0].dPlanSignDate;
			var dPlanSignDate = moment(a).format('YYYY-MM-DD');
			jQuery("#signedDate").val(dPlanSignDate);
			jQuery("#projectName").val(selects[0].cProjectName);
			jQuery("#payType").val(selects[0].cPayWayMemo);
			jQuery("#guaranteePeriod").val(selects[0].cQualityMemo);
			jQuery("#breakDuty").val(selects[0].cLiabilityMemo);
		}
    	jQuery('#modal-find-qdqydsp').modal("hide");
	});
    //查询要点审批表
    jQuery('#btn-search-hq').on('click',function(){
        serverData2.key=jQuery('#search1-hq').val();
        serverTable2.draw();
    });
    jQuery('#btn-reset-hq').on("click",function(){
    	jQuery('#search1-hq').val('');
    	serverData2.key="";
    	serverTable2.draw();
    });
     // 查看审批
   	jQuery('.btn-audit-nodes').on('click', function () {
   		var selects=getSelect("#dataTable",1);
   		if(selects.length==0){
    		   $.springLemonDialog({
    		         content: '请选择要查看的记录',// 确认文本
    		         clickButton: function (sender, modal, index) {// 按钮事件处理
    		             $(this).closeDialog(modal);
    		         }
    		   }); 
   		}else if(selects.length>1){
    		   $.springLemonDialog({
    		         content: '一次只能查看一条记录的审批',// 确认文本
    		         clickButton: function (sender, modal, index) {// 按钮事件处理
    		             $(this).closeDialog(modal);
    		         }
    		   }); 
    	}else{
    		if(selects[0].auditState=='未提交'){
    			$.springLemonDialog({
   		         content: selects[0].supplierCode+'还没有提交审批',// 确认文本
   		         clickButton: function (sender, modal, index) {// 按钮事件处理
   		             $(this).closeDialog(modal);
   		         }
    			}); 
    	   		return;
    	   	}
    		var url=window.rootPath+'/ui/task/audit-nodes/contract/'+selects[0].contractId+'?contract-type='
    		+selects[0].contractType+'&contract-code='+selects[0].supplierCode;
       		jQuery.get(encodeURI(url),null,function(html){
       			jQuery('#modal-audit-nodes-content').html(html);
       			jQuery('#modal-audit-nodes').modal("show");
       		});
    	}
   	});	   	 
    
    // 撤销审批
    jQuery(".app-btn-audit-cancel").on('click',function() {
        var selects = getSelect("#dataTable", 1);
        if (selects.length > 1) {
            $.springLemonDialog({
                content: '一次只能对一条记录撤销审批',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
        }
        else if (selects.length == 0) {
            $.springLemonDialog({
                content: '请选择要撤销审批的记录',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
        } else if (selects.length == 1) {
            if (selects[0].auditState != '已提交') {
            	$.springLemonDialog({
                    content: selects[0].supplierCode + '已不可撤销！\n只有“已提交”状态可撤销',// 确认文本
                    clickButton: function (sender, modal, index) {// 按钮事件处理
                        $(this).closeDialog(modal);
                    }
                });
                return;
            }

            var contractId = selects[0].contractId;
            var contractType = selects[0].contractType;
            var contractCode = selects[0].supplierCode;

            jQuery.springLemonDialog({
                content: '确认撤销合同审批：' + contractCode + '？',// 确认文本
                clickButton: function (sender, modal, index) {
                    if (index == 1) {
                    	 jQuery(this).closeDialog(modal);
                        return;
                    }
                    var url = window.rootPath + '/ui/task/cancel/contract/' + contractId
                        + '?contract-type=' + contractType;
                    jQuery.post(encodeURI(url), null, function (data) {
                        if (data.code == 0) {
                        	  jQuery(this).closeDialog(modal);
                            window.location = window.rootPath
                                + "/ui/contract/";
                        }
                    });
                    jQuery(this).closeDialog(modal);
                }
            });


        }//end of if

    });
	
    

    
    
})();